"Go" JS gzip encrypt string and base64 output

Source: Internet
Author: User
Tags base64

http://blog.csdn.net/zunwei/article/details/49886115

Recently encountered some problems in development, about JS how to give a string to the byte stream encryption. The following is a detailed approach,

First introduce pako_deflate.min.js (https://github.com/nodeca/pako/tree/master/dist) plug-in, attachments can be downloaded

Demo

var Applistjson = "{" "Name": "Lvzunwei"} ";

Gzip Encryption: Note Here is the default Gzip method instead of Pako.gzip (applistjson,{to: "string"});

var pakostring = Pako.gzip (Applistjson);

The byte stream after direct gzip cannot be encrypted by a normal Base64 string, because Base64 string encryption intelligently receives a string, so if you use the above pakostring directly base64 will report JS Error!

Base64 byte stream encryption I found a JS on the Geihub but need to change a little bit (HTTPS://GITHUB.COM/BEATGAMMIT/BASE64-JS):

Open the B64.js edit under Lib to remove the red-and-white sections

Uint8tobase64 (pakostring);

This allows you to complete the Base64 encryption of the string gzip encryption and byte stream!

"Go" JS gzip encrypt string and base64 output

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.