After mcrypt_encrypt () is encrypted in Chinese, it will be garbled.

Source: Internet
Author: User
What should I do? after mcrypt_encrypt () is encrypted in Chinese, it is displayed as garbled characters. after the Restoration, the Chinese & nbsp; is displayed on the page. it is not a coding problem & nbsp; why is it garbled after encryption? What should I do? & lt; meta & nbsp; http-equiv = "Content-Type" what should I do? after mcrypt_encrypt () is encrypted in Chinese, it is displayed as garbled characters.
Chinese characters displayed on the page are not encoding problems
Why is it garbled after encryption? What should I do?




Header ("Content-Type: text/html; charset = utf-8 ");

$ Str = "Moonlight in front of bed, suspected to be frost on the ground"; // encrypted content
$ Key = "key: 111"; // key
$ Cipher = MCRYPT_DES; // encryption algorithm type
$ Mode = MCRYPT_MODE_ECB; // encryption algorithm mode
$ Iv = mcrypt_create_iv (mcrypt_get_iv_size ($ cipher, $ mode), MCRYPT_RAND); // Initialization vector
Echo "before encryption". $ str ."
";
// Encryption
$ Str_encrypt = mcrypt_encrypt ($ cipher, $ key, $ str, $ mode, $ iv );
Echo "encrypted". $ str_encrypt ."
";
// Restore
$ Str_decrypt = mcrypt_encrypt ($ cipher, $ key, $ str_encrypt, $ mode, $ iv );
Echo "restore". $ str_decrypt ."
";

?>


------ Solution --------------------
// Restore
$ Str_decrypt = mcrypt_decrypt ($ cipher, $ key, $ str_encrypt, $ mode, $ iv );
Echo "restore". $ str_decrypt ."
";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.