We help IT Professionals succeed at work.

Encryption/Decryption with php and Delphi

Andrea Matthiae
on
High Priority
254 Views
Last Modified: 2019-07-18
Hi Experts!
I am having a lot of trouble finding a code that encrypts a string (max 100 characters) with php code and that it is possible to decrypt the same string in Delphi (Tokyo version 10.2).
I searched a lot online and also on EE. Such as here:

https://stackoverflow.com/questions/7052219/php-to-delphi-and-back-encryption-decryption-using-rijndael
https://www.experts-exchange.com/questions/26199791/Encrypt-in-Delphi-Decrypt-in-PHP-and-Vice-Versa.html
https://www.experts-exchange.com/questions/26402183/Rijndael-128-bit-Encryption-with-Delphi-and-PHP.html

But none of these works!

The solution to use the base64 encode/decode is not enough.
I would appreciate Rijndael 128 bit Encryption or better.

Many thanks in advice.
Comment
Watch Question

ste5anSenior Developer
CERTIFIED EXPERT

Commented:
The last time I did crypto in Delph, I had to use DEC (Delphi Encryption Compendium). But I don't know whether it runs on Tokyo or whether it supports ciphers which are also available in PHP.
Another product is LockBox.
Software Developer / Linux System Administrator
CERTIFIED EXPERT
Commented:
One of the problems may well be that the libraries referred to are quite old and older libraries with Tokyo do not always work so well. You would be better off, as Ste5an suggests, using a library that specifically supports the version of Delphi that you are using.

Also check that the problems you are facing are not down to character encoding issues. My understanding is that many crypto libraries that are available for Delphi work on buffers of single bytes behind the scenes, and do not in any way consider character encoding and multi-byte character sets. If for some reason the PHP library is taking character encoding into consideration, I wonder if that is the source of the problem. I am not a crypto expert, so please do take comments in this paragraph with a degree of caution.
CERTIFIED EXPERT
Top Expert 2014

Commented:
How is the original string encoded in PHP?  If the string is unicode, it might encrypt differently than ASCII.
Andrea MatthiaeSoftware engineering

Author

Commented:
Hi aikimark,
thanks for your response.
The original string is ASCII.
Martyn SpencerSoftware Developer / Linux System Administrator
CERTIFIED EXPERT

Commented:
You will want to ensure that the character encoding in Delphi and PHP are identical when handling the encryption and decryption, as i alluded to in my comment.
Andrea MatthiaeSoftware engineering

Author

Commented:
Not found a solution!

Thanks anyway to Martyn Spencer.
Because what he wrote is what I found after numerous attempts