import CryptoJS from 'crypto-js'
const keyStr = 'XXXXXXX' // 秘钥
// 加密
export const encryptAes = message => {
var key = CryptoJS.enc.Utf8.parse(keyStr)
var srcs = CryptoJS.enc.Utf8.parse(message)
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
}
// 解密
export const decryptAes = message => {
var key = CryptoJS.enc.Utf8.parse(keyStr)
var decrypt = CryptoJS.AES.decrypt(message, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}
来源:CSDN
作者:周皮皮皮皮皮皮
链接:https://blog.csdn.net/qq_32439381/article/details/104658625