1

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>";
?>
2
  • 1
    Instead of echo base64_encode($decrypted), why don't you.. echo the $decrypted? Commented Jul 6, 2011 at 15:53
  • I also needed to echo $decrypted. Commented Jul 6, 2011 at 15:59

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mark, I was looking at it for fifteen minutes completely dumbfounded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.