2
mcrypt_decrypt與TripleDes的和CBC工作不正確
按照上面的截圖我的解碼數據會看到這樣的時候,我可以在瀏覽器中查看源。否則解密正確,但由於此問題,不會正確存儲會話。感謝提前。
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;
}
請張貼編碼。 –