I recently in the front-end use of cookies to save the password to the front-end to do encryption work, contact Crypto This JS, use is simple, here to record.
You can download the JS on this GitHub https://github.com/brix/crypto-js, it can introduce the required encryption method of JS, it can also introduce a crypto-js.js this file, it is equivalent to the introduction of all the encryption method, I am using the latter to introduce all the encrypted files at once, this file is not very large, but also acceptable.
Because my needs are password reversible, there is a certain degree of security, so using DES or AES, I am using AES, just on-line has a use of AES example, directly to use the
functionGetaesstring (DATA,KEY,IV) {//Encrypt varKey =CryptoJS.enc.Utf8.parse (key); varIV =CryptoJS.enc.Utf8.parse (iv); varencrypted =CryptoJS.AES.encrypt (Data,key, {iv:iv, Mode:CryptoJS.mode.CBC, Padding:crypto JS.PAD.PKCS7}); returnEncrypted.tostring ();//returns a ciphertext in the base64 format}functionGetdaesstring (ENCRYPTED,KEY,IV) {//decryption varKey =CryptoJS.enc.Utf8.parse (key); varIV =CryptoJS.enc.Utf8.parse (iv); vardecrypted =CryptoJS.AES.decrypt (Encrypted,key, {iv:iv, Mode:CryptoJS.mode.CBC, Padding:c RYPTOJS.PAD.PKCS7}); returndecrypted.tostring (CryptoJS.enc.Utf8); }functionGetaes (data) {//Encrypt varKey = ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ';//secret key varIV = ' 1234567812345678 '; varEncrypted =getaesstring (DATA,KEY,IV);//Ciphertext varEncrypted1 =CryptoJS.enc.Utf8.parse (encrypted); returnencrypted;}functionGetdaes (data) {//decryption varKey = ' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ';//secret key varIV = ' 1234567812345678 '; varDecryptedstr =getdaesstring (DATA,KEY,IV); returndecryptedstr;}
We can replace both key and IV, but we need to ensure that the encryption key and VI remain the same
Front end is encrypted with crypto.js