0

我的 openssl_encrypt 函数有问题。

在 aes-128-cbc 中,为什么函数返回一个 32 字节字符串和一个 16 字节字符串作为输入?

样本 :

$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>';

结果:openssl_encrypt 长度:32 mcrypt_encrypt 长度:16

4

1 回答 1

1

谢谢托帕科。

根据您的评论,我们在 php openssl 源代码中进行调查。我们找到“OPENSSL_NO_PADDING”选项,现在它工作正常。

$binaryK0 = openssl_encrypt(hex2bin("00000000000000000000000000000000"),"AES-128-CBC", hex2bin("00112233445566778899AABBCCDDEEFF"),**OPENSSL_NO_PADDING**, hex2bin("00000000000000000000000000000000"));
于 2019-10-21T14:54:25.100 回答