【发布时间】:2015-10-09 16:19:24
【问题描述】:
根据上面的屏幕截图,当我可以在浏览器中查看源代码时,我的解码数据将如下所示。否则,由于此问题,请正确解密但不能正确存储在会话中。提前致谢。
function decrypt($data, $key) {
$iv = chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0); //8 bytes array filled with zeros
$key = mb_convert_encoding($key, 'UTF-16LE');
$key = md5($key, true);
$key = $key . $key;
$tripleKey = substr($key, 0, mcrypt_get_key_size(CIPHER, MODE));
$decodedText = mcrypt_decrypt(CIPHER, $tripleKey, base64_decode($data), MODE, $iv);
// check and remove PKCS#7 padding
if (!$decodedText) {
return $decodedText;
}
$lastByte = ord($decodedText[strlen($decodedText) - 1]);
if ($lastByte == 0 || $lastByte > mcrypt_get_block_size(CIPHER, MODE)) {
return FALSE;
}
$paddingText = substr($decodedText, -$lastByte, $lastByte);
$decodedText = substr($decodedText, 0, -$lastByte);
if ($paddingText != str_repeat(chr($lastByte), $lastByte)) {
return FALSE;
}
return $decodedText;
}
【问题讨论】:
标签: php codeigniter codeigniter-2 mcrypt