PHP加密错误,解密失败


PHP mcrypt error, unsuccessful decryption

下面的代码不能正确解密明文。有人知道为什么解密不会给我正确的纯文本吗?

<?php
$key = "ShHhd8a08JhJiho98ayslcjh";
$plaintext = "Let us meet at 9 o'clock at the secret place.";
$cyphertext = "arTdPqWOg6VppOqUD6mGITjb24+x5vJjfAufNQ4DN7rVEtpDmhFnMVM+W/WFlksR";

$encrypted = mcrypt_encrypt(MCRYPT_3DES, $key, $plaintext, MCRYPT_MODE_ECB);
$decrypted = mcrypt_decrypt(MCRYPT_3DES, $key, $cyphertext, MCRYPT_MODE_ECB);
echo base64_encode($encrypted)."</br>";
echo base64_encode($decrypted)."</br>";
?>

你的密文看起来已经是base64编码了,所以你是在比较苹果/橘子。假设首先正确生成了$cyphertext,您必须比较

$cyphertext == base64_encode($encrypted)

获得有效的比较,或者

base64_decode($cyphertext) == $encrypted