When the back end writes the link and asks the front end to obtain the unique identifier OpenID, wechat authorization can be realized. However, for the sake of security, it is better not to expose the obtained information on the website, so the back end needs to encrypt the user’s information and let the front end decrypt it.

More secure encryption:

Des Encryption Mode

CBC is mode

PKCS5Padding is padding schemes

Before decryption, the back end needs to provide the pre-encrypted data (convenient to check whether the data is correct), the encrypted data, the secret key, and the IV offset, but generally want to try one by one. The one I used was DES /CBC/Paddingkey

The steps are as follows:

You can download it using NPM and then write a utility class for encryption and decryption

    npm install crypto-js
Copy the code

1. Introduce the crypto.js plug-in

< script SRC = "https://cdn.bootcss.com/crypto-js/3.1.9-1/crypto-js.min.js" > < / script >Copy the code

2. Decrypt the code executed

<script> window.onload = function () {let value = 'escape(value) console.log' ',jiami) let str1 = encryptByDES(jiami); Console. log(' Encrypted data :',str1.toString().touppercase ()) let str2 = encodeURI(decryptByDESModeEBC(str1)); Console. log(' decrypted data :',str2)} // Encrypted private key Var keyHex = cryptojs.enc.utf8.parse (key); // encryptByDES(message) {var keyHex = cryptojs.enc.utf8.parse (key); Encrypt (message, keyHex, {iv: iv, mode: encrypted). Encrypt (message, keyHex, {iv: iv, mode: encrypted). CryptoJS.mode.CBC, padding: CryptoJS.pad.Paddingkey }); Out / / encryption is a hexadecimal string / / var result_value = CryptoJS enc. Base64. Parse (result_value) / / / / var word2 = RSAdecrypt (parseStr) // var parseStr = words.toString(CryptoJS.enc.UTF-8) return encrypted.ciphertext.toString(); } function decryptByDESModeEBC(ciphertext) {var keyHex = cryptojs.enc.utf8.parse (key); // Convert decrypted data from hexadecimal string to character byte array var decrypted = cryptojs.desed.decrypt ({ciphertext: CryptoJS.enc.Hex.parse(ciphertext) }, keyHex, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Paddingkey }); / / output in the form of utf-8 after decryption content / / var value = CryptoJS. Enc. Base64. Parse var result_value = (value) decrypted.toString(CryptoJS.enc.Utf8) // var result_value = CryptoJS.enc.Base64.parse(result_value) // // var word2 = RSAdecrypt(parseStr) // var parseStr = words.toString(CryptoJS.enc.UTF-8) return result_value } </script>Copy the code

I used it in vuejs for a licensing feature and found crypto-JS to be pretty good.