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>";
?>
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