【发布时间】:2015-01-13 07:13:06
【问题描述】:
我尝试使用 rinjndael_128 密码的 ecb 模式使用 16 位密钥加密数据。加密成功,我也可以成功解密加密数据。但问题是,mcrypt_encrypt 函数返回的是乱码字符串。我想以十六进制格式查看此结果。
当我使用在线工具获取相同的数据时,得到这个十六进制值作为结果bd61ce515890e2e3fb5e404bbe886cc2
代码
$key = pack('H*', "07070609070306050601070007000700");
$plaintext = "2dfb0998b2f76f35f5b08972b57cfbfc";
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB);
$ciphertext_base64 = base64_encode($ciphertext);
echo "encrypted - text: ".$ciphertext . "<br>";
echo "encrypted base 64 encoded - text: ".$ciphertext_base64 . "<br>";
$ciphertext_dec = base64_decode($ciphertext_base64);
$plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key,$ciphertext_dec, MCRYPT_MODE_ECB);
echo "decrypted data - text: ".$plaintext_dec . "<br>";
结果:
before encryption - text: 2dfb0998b2f76f35f5b08972b57cfbfc
encrypted - text: (MÓx‹ÓåBÖ i½4²5žNUXÃè/Óë£@ö
encrypted base 64 encoded - text: KE3TeIsa0+VC1g1pCL00sjWeTlVYw+iNgS/TEOujQPY=
decrypted data - text: 2dfb0998b2f76f35f5b08972b57cfbfc*
【问题讨论】:
标签: php encryption aes encryption-symmetric