1. Use crypto-JS for encryption

Download:

npm install crypto-js --save
Copy the code

2, use,

/ * * *@Date: 
 * @Author: 
 * @FilePath: 
 * @Description: aes encryption And into Base64 * online validation: https://tool.lmeee.com/jiami/aes * /
const CryptoJS = require('crypto-js');  // Reference the AES source js
const key = CryptoJS.enc.Latin1.parse(""); // A 16-bit string key
const iv = CryptoJS.enc.Latin1.parse(""); // 16-bit string key offset

// Encryption method
export function Encrypt(word) {
    return CryptoJS.AES.encrypt(word, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        // This parameter can be changed
        padding: CryptoJS.pad.Pkcs7
    }).toString();
}

// Decrypt method
export function Decrypt(word) {
    let decrypted = CryptoJS.AES.decrypt(word, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    return decrypted.toString(CryptoJS.enc.Utf8);
}

Copy the code