madCrypt and PHP - simple example needed
-
- Posts: 1
- Joined: Fri Sep 26, 2008 11:24 pm
madCrypt and PHP - simple example needed
Hello!
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.
***** DELPHI
var
IV: Int64;
S, Pass, Enc, Dec: string;
...
S := 'Some text';
IV := 456789; //a number
Pass := 'password';
//encode
Enc := S;
Encrypt(Enc, Pass, IV);
Enc := Encode(Enc); // SgNc9xZtzEFH3Gt74JHPJQ==
//decode
Dec := Decode(Enc);
Decrypt(Dec, Pass, IV);
//OK: now Dec = S
***** PHP
$S = 'Some text';
$IV = 'abcdefgh'; //?????
$Pass = 'password';
//encode
$Enc = $S;
$Enc = mcrypt_cfb(MCRYPT_BLOWFISH, $Pass, $Enc, MCRYPT_ENCRYPT, $IV); //mcrypt_cbc ???
$Enc = base64_encode($Enc); // L6IKpL6JdFJe
echo $Enc .'<br>';
//decode
$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.
Thanks!
Bart
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.
***** DELPHI
var
IV: Int64;
S, Pass, Enc, Dec: string;
...
S := 'Some text';
IV := 456789; //a number
Pass := 'password';
//encode
Enc := S;
Encrypt(Enc, Pass, IV);
Enc := Encode(Enc); // SgNc9xZtzEFH3Gt74JHPJQ==
//decode
Dec := Decode(Enc);
Decrypt(Dec, Pass, IV);
//OK: now Dec = S
***** PHP
$S = 'Some text';
$IV = 'abcdefgh'; //?????
$Pass = 'password';
//encode
$Enc = $S;
$Enc = mcrypt_cfb(MCRYPT_BLOWFISH, $Pass, $Enc, MCRYPT_ENCRYPT, $IV); //mcrypt_cbc ???
$Enc = base64_encode($Enc); // L6IKpL6JdFJe
echo $Enc .'<br>';
//decode
$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.
Thanks!
Bart
same problem
i am having same problem , anyone can post a working example please
madcrypt/php
I have a PHP app encrypting data. I can succesfully decrypt it in JAVA using blowfish CBC.
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
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
Oh well, I'm not really an encryption expert. It's been quite a while that I wrote madCrypt and I don't remember the exact details of the algorithm. I don't even know what CBC means exactly right now.
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.
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.
unfortunately i'm even less of an encryption expert.
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
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
Ok.. done a bit of digging
it seems that Turbo Power (Open Source on www.sourceforge.net)
it has a blowfish CBC cipher
it seems that Turbo Power (Open Source on www.sourceforge.net)
it has a blowfish CBC cipher