import CryptoJS from 'crypto-js'
const AES_KEY = '0ca03a92751282f6ee05f8e6e42020b5'
/**
* 加密
* @param {*} str
* @returns
*/
export function aesEncode(str) {
const key = CryptoJS.enc.Utf8.parse(AES_KEY)
const word = CryptoJS.enc.Utf8.parse(str)
const encrypted = CryptoJS.AES.encrypt(word, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
}
/**
* 解密
* @param {*} passPhrase
* @returns
*/
export function aesDecode(passPhrase) {
const key = CryptoJS.enc.Utf8.parse(AES_KEY)
const decrypt = CryptoJS.AES.decrypt(passPhrase, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}
引入
import { aesEncode } from './aes.js'
使用
aesEncode(//需要加密的内容)