[英]Wrong result when using mycrypt_cfb
Here are the encryption and decryption functions: 这是加密和解密功能:
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));
}
Now: 现在:
$key = "11111";
$str = "1000181";
echo decrypt($key,encrypt($key,$str));
The result is 100018, missing the last "1". 结果是100018,缺少最后一个“ 1”。
Why? 为什么?
The solution was: 解决方案是:
remove the trim & chop calls from decrypt() 从解密()中删除修剪和砍切调用
Answer was in the comments, by KiNgMaR 答案在评论中,由KiNgMaR撰写
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.