JS+AES解密(CBC模式、输出HEX)

       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)
        }
上一篇:替换字符串


下一篇:XOR加密