i tried to encrypt a text in as3crypto via the demo app.
now i am trying to decrypt the crypted text via php but it seems that the text is not properly decrypted. has anyone know how to properly decrypt it via PHP? or am I doing it wrong? please enlighten me...
here's the scenario:
encrypt this in http://crypto.hurlant.com/demo/:
encryption: AES
mode: CBC
padding: none
key: 11918f8bcd112e92744125008722050c
text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut massa nec purus laoreet posuere quis vitae tortor.
initialize vector: leave it blank
press encrypt. select base64 and copy the cipher text.
make a php script that has these codes and run it:
$cipher = MCRYPT_RIJNDAEL_128;
$mode = MCRYPT_MODE_CBC;
$key = "11918f8bcd112e92744125008722050c";
$cipher = "PLACE CIPHER TEXT HERE...";
$data = base64_decode($cipher);
echo mcrypt_decrypt($cipher, $key, $data, $mode);
the issue probably lies in your key. While you can feed a hex string to as3crypto and it will know what do to with it,
mcrypt_decrypt
will interpret each character as it's underlying ASCII value (like a = 97) instead of it's hexadecimal value (a = 10). Use the hex2bin method to convert the hex string into a byte string, and your decryption should probably work fine.also, an issue may rest with different ideas of a default IV (initialization vector) between as3crypto and php. Since you are using CBC mode, you should be specifying an IV, just as a good security practice. also be aware of the potential pitfalls similar to those with your key, of specifying a hex string in as3 and needing to convert it in php.
This would work:
PHP code:
And here is AS3 code