我正在使用 php 解密来检查:回复请求的电子邮件地址与发送请求的电子邮件地址相同。
这是代码,但在底部它简单失败。
网址很简单:
blah.com/page?keyemail=fSHEk8KC17siklGHsj0HJA==
下面的代码还显示了我为确保加密/解密工作正常所做的一些测试......我回显了代码以查看发生了什么
$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;
当我回显 $email_key3 以某种方式编码时返回的内容 - 它应该是 me@me.com
我可能错过了一些明显的东西,但它让我失去了!