dongshao8566 2011-07-06 15:50
浏览 43
已采纳

PHP mcrypt错误,解密失败

The code below does not decrypt the plaintext correctly. Does anyone know why the decrypt will not give me the correct plain text?

<?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>";
?>
  • 写回答

1条回答 默认 最新

  • douciping4283 2011-07-06 15:54
    关注

    Your cyphertext looks to be base64-encoded already, so you're comparing apples/oranges. Assuming your $cyphertext is correctly generated in the first place, you'd have to compare

    $cyphertext == base64_encode($encrypted)
    

    to get a valid comparison, or

    base64_decode($cyphertext) == $encrypted
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?