Base64 Chinese cannot encrypt the problem

Source: Internet
Author: User

Recently, Base64.js has been used to encrypt URL parameters, and both letters and numbers can be well encrypted/decrypted. However, when testing Chinese, it is not possible to convert, it seems that base64.js does not support medium characters.

Lenovo to encodeURI () encoding/decoding of URLs, but encodeURI, decodeURI can only convert Chinese characters, not support letters and numbers. So want to be able to use encodeURI encoding and then base64 encryption, get the key first with Base64 decryption, and then use decodeURI decoding. It's been tested successfully! Thus, the encryption and decryption of numbers, letters and Chinese characters are realized. The following is the test code:

<script type= "Text/javascript" src= "js/base64.js" ></script><script type= "Text/javascript" >functionBian () {varval = document.getElementById ("BB"). Value; varCom=Base64Encode (encodeURI (Val)); varres = document.getElementById ("Result"); Res.value=com; }        functionJie () {varval = document.getElementById ("BB"). Value; varCom=decodeURI (Base64decode (Val)); //document.write (COM);            varres = document.getElementById ("Result"); Res.value=com; }    </script>

<input type= "text" id= "BB"/><input type= "button" value= "Encode" onclick= "Bian ()" ><input type= "button" Value= "decoding" onclick= "Jie ()" > <br/><input type= "text" id= "result" >

Base64 Chinese cannot encrypt the problem

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.