ASE加密和解密
程序员文章站
2024-03-14 15:38:58
...
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()
}
下一篇: iOS 对称算法DES加解密