以下代码未正确解密明文。有谁知道为什么解密不会给我正确的纯文本?
<?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>";
?>
答案 0 :(得分:1)
你的密文似乎已经是base64编码的,所以你要比较苹果/橘子。假设您的$cyphertext
首先正确生成,则必须进行比较
$cyphertext == base64_encode($encrypted)
获得有效的比较,或
base64_decode($cyphertext) == $encrypted