1、cnpm i crypto-js --save
2、aes.js
var CryptoJS = require("crypto-js");
/**
* 加密
*/
export const encrypt = (word) => {
var key = CryptoJS.enc.Utf8.parse("46cc793c53dc451b");//秘钥 后端通过秘钥进行解密
var srcs = CryptoJS.enc.Utf8.parse(word);
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
/**
* 解密
*/
export const decrypt = (word) => {
var key = CryptoJS.enc.Utf8.parse("46cc793c53dc451b");
var decrypt = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
import { encrypt } from '@/utils/aes.js';
encrypt(password); // 调用