I am using php decrypion to check that: an email address replying to a request is the same email address which was sent the request.
This is the code but at the bottom it simpy fails.
The url is simply:
blah.com/page?keyemail=fSHEk8KC17siklGHsj0HJA==
The code below also shows some tests i did to make sure the encrypt/decrypt were working ok... I echo'd down the code to see what was going on
$key="XiTo74UI09wwe4YeUmuvbL0E";
$iv = mcrypt_create_iv (mcrypt_get_block_size (MCRYPT_TripleDES, MCRYPT_MODE_CBC), MCRYPT_DEV_RANDOM);
// Encrypting
function encrypt($string, $key) {
$enc = "";
global $iv;
$enc=mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_ENCRYPT, $iv);
return base64_encode($enc);
}
// Decrypting
function decrypt($string, $key) {
$dec = "";
$string = trim(base64_decode($string));
global $iv;
$dec = mcrypt_cbc (MCRYPT_TripleDES, $key, $string, MCRYPT_DECRYPT, $iv);
return $dec;
}
// test example
$email = 'me@me.com';
echo "email is $email<br /><br />";
$email_key = encrypt($email, $key);
echo "key is $email_key<br /><br />";
$email_key2 = decrypt($email_key, $key);
echo "decrypted is $email_key2<br /><br />";
// END test example, all is ok
// this is the code that fails
$to_de = $_GET[keyemail];
echo "keyemail again is $to_de<br /><br />";
$email_key3 = decrypt($to_de, $key);
echo $email_key3;
What is being returned when I echo $email_key3 is encoded somehow - it should be me@me.com
I'm probably missing something obvious but it's lost me!