怎么处理mcrypt_encrypt() 加密中文后,就显示为乱码了,还原后也是

WBOY
Release: 2016-06-13 11:15:39
Original
1948 people have browsed it

怎么办mcrypt_encrypt() 加密中文后,就显示为乱码了,还原后也是
页面能显示中文 不是编码问题 
为什么加密后就成乱码?要怎么处理


<br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><br /><?php<br />header("Content-Type:text/html; charset=utf-8");<br /><br />$str="床前明月光,疑是地上霜"; //被加密的内容<br />$key="key:111"; //密匙<br />$cipher=MCRYPT_DES;  //加密算法类型<br />$mode=MCRYPT_MODE_ECB;  //加密算法模式<br />$iv=mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode),MCRYPT_RAND); //初始化向量<br />echo "加密前".$str."<br>";<br />//加密<br />$str_encrypt=mcrypt_encrypt($cipher,$key,$str,$mode,$iv);<br />echo "加密后".$str_encrypt."<br>";<br />//还原<br />$str_decrypt=mcrypt_encrypt($cipher,$key,$str_encrypt,$mode,$iv);<br />echo "还原".$str_decrypt."<br>";<br /><br />?><br /><br />
Copy after login


------解决方案--------------------
//还原
$str_decrypt=mcrypt_decrypt($cipher,$key,$str_encrypt,$mode,$iv);
echo "还原".$str_decrypt."
";
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template