Has anyone a simple example how to:
1) encrypt a string in Delphi and decrypt it in PHP
2) encrypt a string in PHP and decrypt it in Delphi.
Below is my code - it is working, but I do not know:
1) how to convert IV between Delphi (Int64) and PHP (string)
2) what function to use in PHP to encrypt/decrypt (mcrypt_cfb, mcrypt_cbc, ...)
to make encryption compatible between Delphi and PHP.
S, Pass, Enc, Dec: string;
S := 'Some text';
IV := 456789; //a number
Pass := 'password';
Enc := S;
Encrypt(Enc, Pass, IV);
Enc := Encode(Enc); // SgNc9xZtzEFH3Gt74JHPJQ==
Dec := Decode(Enc);
Decrypt(Dec, Pass, IV);
//OK: now Dec = S
$S = 'Some text';
$IV = 'abcdefgh'; //?????
$Pass = 'password';
$Enc = $S;
$Enc = mcrypt_cfb(MCRYPT_BLOWFISH, $Pass, $Enc, MCRYPT_ENCRYPT, $IV); //mcrypt_cbc ???
$Enc = base64_encode($Enc); // L6IKpL6JdFJe
echo $Enc .'<br>';
$Dec = base64_decode($Enc);
$Dec = mcrypt_cfb(MCRYPT_BLOWFISH, $Pass, $Dec, MCRYPT_DECRYPT, $IV);
$Dec = trim($Dec, "\0");
echo $Dec .'<br>';
//OK: now $Dec = $S
Sorry for asking such a simple question, but I do not know PHP enough and I'm sitting half a day without a solution...
I would be VERY grateful for any suggestions.
I presume that the reason madCrypt cannot decrypt PHP blowfish data is that madCrypt has no CBC decrypt option.
If you could add a decrypt type as a paremeter, I'm sure we will be able to decrypt PHP encrypted data
But anyway, madCrypt is open source. Maybe if you know a bit more about decryption than I do, you could write a patch that adds CBC support? If you find a way to make it work, please let me know.
the only reason i know PHP uses CBC (instead of ECB) is that I struggled to get java decrypting my info. I only got it working when I told java to create a cipher like this
Cipher cipher = Cipher.getInstance("Blowfish/CBC/NoPadding");
after that it worked fine...
I will have a look at it and see what I can do, but my knowledge is very limited