openssl_encrypt last Bytes是错误的

时间:2017-04-19 21:11:06

标签: php encryption

我遇到openssl_encrypt时遇到问题。最后8个字节似乎是错误的。当我将加密的字符串与在线工具(http://des.online-domain-tools.com/link/bf9973gpgFBNsITuh/)的字符串进行比较时,除最后8个字节外,它们完全相同。使用AES,最后16个字节将是不同的。

有人可以解释一下这个区别吗?任何帮助都将受到欢迎。

PHP代码:

$method = 'DES-CBC';
$cipherKey = 'CsflsUHV';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$iv = $iv ^ $iv; // this will ensure an IV composed of zeroes only
$plainText = 'This is my plain text to encrypt.';
echo implode(' ', str_split(bin2hex(openssl_encrypt($plainText, $method, $cipherKey, OPENSSL_RAW_DATA, $iv)), 2));

结果(顶部是PHP,底部是des.online-domain-tools.com):

9f 47 5d 8b 7d c3 4b 55 96 b9 27 86 c2 e8 d1 fc 68 7d 6e 83 49 fa 3b af 04 73 da e8 c8 3c a4 bc 3a 94 c8 c3 ab e6 36 22

9f 47 5d 8b 7d c3 4b 55 96 b9 27 86 c2 e8 d1 fc 68 7d 6e 83 49 fa 3b af 04 73 da e8 c8 3c a4 bc e6 6d 49 c9 3d 44 ca e7

注意:我知道DES已经过时,IV不应该是零,但这是一个简单的例子来理解出了什么问题。

感谢您的帮助。

0 个答案:

没有答案