我正在使用这个功能:
function encryptData($value) {
$key = "top secret key";
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
return $crypttext;
}
function decryptData($value) {
$key = "top secret key";
$crypttext = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}
登录.php
$time = time() + 60*60*24*30*12; //store cookie for one year
setcookie('cookie_name', encryptCookie('username'), $time, '/');
$cookie_value = decryptCookie($_COOKIE['cookie_name']);
cookie 已设置并且正在工作。
问题:
- 我将如何解密 的内容
$_COOKIE['cookie_name']
并打印它?
我需要在这一行打印它:
so.addVariable("uid", "<? if ($_COOKIE['username']) print $_COOKIE['username']; ?>");