mcrypt_decrypt 三元组和 cbc 无法正常工作

mcrypt_decrypt with tripledes and cbc not working proper

根据上面的屏幕截图,当我可以在浏览器中查看源代码时,我的解码数据将如下所示。否则,由于提前 problem.Thanks problem.Thanks,正确解密但不能正确存储在会话中。

  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;
}

请尝试按照以下更新行。

$decodedText = str_replace("[=10=]", "", $decodedText);
return $decodedText;