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
>
<</span>html lang="en">
<</span>head>
<</span>meta charset="UTF-8">
<</span>title>title
JavaScript enables front-end AES encryption and decryption capabilities