laurent MENARD
laurent MENARD

Reputation: 11

PHP : openssl_encrypt result 32o string with 16o input string

I have a problem with the openssl_encrypt function.

In aes-128-cbc, why function return a 32-bytes string with a 16-bytes string as input?

Sample :

$binaryK0 = openssl_encrypt(hex2bin("00000000000000000000000000000000"),"AES-128-CBC", hex2bin("00112233445566778899AABBCCDDEEFF"),OPENSSL_RAW_DATA, hex2bin("00000000000000000000000000000000"));
echo "openssl_encrypt length:".strlen($binaryK0).'<br>';
$binaryK0 = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hex2bin("00112233445566778899AABBCCDDEEFF"), hex2bin("00000000000000000000000000000000"), MCRYPT_MODE_CBC, hex2bin("00000000000000000000000000000000"));
echo "mcrypt_encrypt length:".strlen($binaryK0).'<br>';

Result : openssl_encrypt length:32 mcrypt_encrypt length:16

Upvotes: 0

Views: 245

Answers (1)

laurent MENARD
laurent MENARD

Reputation: 11

Thank you Topaco.

With your comment, we invetigate in php openssl source code. We find "OPENSSL_NO_PADDING" option and now it's work fine.

$binaryK0 = openssl_encrypt(hex2bin("00000000000000000000000000000000"),"AES-128-CBC", hex2bin("00112233445566778899AABBCCDDEEFF"),**OPENSSL_NO_PADDING**, hex2bin("00000000000000000000000000000000"));

Upvotes: 1

Related Questions