I have a C++ application that's using Crypto++ to send encrypted data to a PHP site. However, when the data's getting to the PHP side, it's not decrypting the data properly.
The C++ / Crypto++ code:
char stupidKey[AES::MAX_KEYLENGTH] = "thisisastupidkeythisisastupidke";
ECB_Mode<AES>::Encryption aes((byte *)stupidKey, AES::MAX_KEYLENGTH);
std::string cypher;
StringSource(aData, true, new StreamTransformationFilter(aes, new StringSink( cypher )));
StringSource(cypher, true, new Base64Encoder( new StringSink(aOutput) ));
The PHP Code:
define('CRYPT_SECRET', 'thisisastupidkeythisisastupidke');
$postData = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,
CRYPT_SECRET, base64_decode($_POST['request']),
MCRYPT_MODE_ECB);
Note: I know ECB is a bad choice of encryption mode, but I'd like to get this working without the added oddities of the IV first, then complicate matters.
I didn't have luck with mcrypt, but openssl seem to work with Crypto++ better.
Here is the Crypto++ code:
And here is the PHP code:
And here is the Crypto++ output:
...and PHP output:
Don't forget to change the key and iv to some smarter values :o)
Looking at the PHP manual (http://php.net/manual/en/function.mcrypt-decrypt.php), MCRYPT_RIJNDAEL_256 is different to AES_256. The first comment offers some help: http://www.php.net/manual/en/function.mcrypt-decrypt.php#105985