使用mycrypt_cfb时结果错误

时间:2009-09-14 06:17:10

标签: php

以下是加密和解密功能:

function encrypt($key, $plain_text) {
    $plain_text = trim($plain_text);
    $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
    $c_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $plain_text, MCRYPT_ENCRYPT, $iv);
    return trim(chop(base64_encode($c_t)));
}

function decrypt($key, $c_t) {
    $c_t =  trim(chop(base64_decode($c_t)));
    $iv = substr(md5($key), 0,mcrypt_get_iv_size (MCRYPT_CAST_256,MCRYPT_MODE_CFB));
    $p_t = mcrypt_cfb (MCRYPT_CAST_256, $key, $c_t, MCRYPT_DECRYPT, $iv);
    return trim(chop($p_t));
}

现在:

$key = "11111";
$str = "1000181";
echo decrypt($key,encrypt($key,$str));

结果是100018,错过了最后一个“1”。
为什么?

1 个答案:

答案 0 :(得分:0)

解决方案是:

  

取下饰边和来自decrypt()

的来电

答案在KiNgMaR的评论中