if (tokenMsgs) {
const response = await getMqttMsgService();
let mqttMsg = response.data.msg;
state.mqttconfigs = mqttMsg;
const aesKeyResData = (await getAesKeyService()).data.msg.part1; //请求key(base64加密后的)
const ivResData = (await getAesKeyService()).data.msg.part2; //请求iv(base64加密后的)
let mykey = decodeURIComponent(escape(window.atob((aesKeyResData).replace(/-/g, "+").replace(/_/g, "/")))); //base64解码的key
let key = CryptoJS.enc.Utf8.parse(mykey) //utf-8
const myiv = decodeURIComponent(escape(window.atob((ivResData).replace(/-/g, "+").replace(/_/g, "/")))) //base64解码的iv
var iiv = CryptoJS.enc.Utf8.parse(myiv) //utf-8
let text = mqttMsg.para2 //需要ase解码的password
let encryptedHexStr = CryptoJS.enc.Hex.parse(text)//指定HEx
let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
//AES解密
let decrypt = CryptoJS.AES.decrypt(srcs, key, {
iv: iiv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.ZeroPadding
})
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
}
JS+AES解密(CBC模式、输出HEX)
最新推荐文章于 2025-10-11 19:28:34 发布
这段代码展示了如何使用CryptoJS库进行AES解密操作。首先通过getMqttMsgService和getAesKeyService获取解密所需的key和iv,然后进行base64解码和UTF-8解析。接着,对需要解密的密码进行AES解密,最后得到解密后的字符串。
389

被折叠的 条评论
为什么被折叠?



