JS front-end AES Encryption
Recently, because of the project needs to do a mitm, suddenly even if the use of HTTPS, can not guarantee the security of the data transfer process. Through a man-in-the-middle attack, you can get all the content of the HTTP protocol directly. So I began to try to do some simple encryption, to a certain extent, to ensure security.
AES encrypts the data, so the client and server use the same secret key. (Only as a demo, the official environment is recommended to use RSA)
First to prepare a plaintext password and encryption using the key
var Source = "ABCDEFG"; var aeskey = "8NONwyJtHesysWpM";
JS encryption padding and mode need to correspond to the server, otherwise it cannot decrypt
Key is a string type and needs to be processed to use//Note: Pkcs5padding and pkcs7padding are the same.
The encrypteddata shown in the previous paragraph is the result of the encryption.
JS Decryption Code
EncryptedData for encrypted data,//directly through JS encrypted data is an object, can not be directly decrypted, the need to convert to Base64 string can be decrypted//server end should return Base64 after the encrypted data EncryptedData = EncryptedData.ciphertext.toString (); var encryptedhexstr = CryptoJS.enc.Hex.parse (EncryptedData);
Results Demo
Tip:aes.js N Oneness
Http://react.file.alimmdn.com/aes.js
Demo Console View
http://react.file.alimmdn.com/aes.html?t=1490179790965
"Source code is as follows"
<!
DOCTYPE html>