JavaScript enables front-end AES encryption and decryption capabilities

Source: Internet
Author: User
Tags base64

Xian Talent NetworkMaster the HTML in theJSFront-end AES Encryption

Recently, because of the project needs to do a MITM, Russia even found that the use of HTTPS, can not ensure the security of the data transmission process. Through the intermediary, can directly get to the HTTP protocol all content. So start by trying to do some simple encryption to a certain extent to ensure security.

This time using AES encryption data, so the client and the Lau Duan use the same secret key. (for presentation only, formal environment referral uses RSA)

First of all, prepare a plaintext password and encryption key

var Source = "ABCDEFG"; var aeskey = "8NONwyJtHesysWpM";

JS encryption padding and mode requirements and service side corresponding, otherwise cannot decrypt

Key is a string type, the requirements are processed and then applied//Note: Pkcs5padding and pkcs7padding are the same

The encrypteddata shown in the previous paragraph is the result of encryption.

JS Decryption Code

EncryptedData for encrypted data,//directly after JS encrypted data is a target, can not be decrypted directly, the need to convert to Base64 string after the decryption//service side should be back Base64 after the encrypted data EncryptedData = EncryptedData.ciphertext.toString (); var encryptedhexstr = CryptoJS.enc.Hex.parse (EncryptedData);


Results Demo

Tip:aes.js N Unity

Http://react.file.alimmdn.com/aes.js

Demo Console View

http://react.file.alimmdn.com/aes.html?t=1490179790965

"Source code as follows"

[HTML] view plain copy

[HTML] view plain copy

  1. >   

  2. <</span>html lang="en">

  3. <</span>head>

  4. <</span>meta charset="UTF-8">

  5. <</span>title>title


JavaScript enables front-end AES encryption and decryption capabilities

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.