const CryptoJS = require('crypto-js'); //引用AES源码js
var o = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ?
function(e) {
return typeof e
}: function(e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol": typeof e
}
var i = {
"Enuu": function Enuu(e, t) {
void 0 === t && (t = !0);
var n = e instanceof Array ? "array": void 0 === e ? "undefined": o(e);
switch ("number" == typeof e && String(e).length > 10 && (n = "string", e = String(e)), n) {
case "string":
return t ? this.jia(e) : this.jie(e);
case "array":
return this.handleArr(e, t);
case "number":
return Number(t ? this.jia(String(e)) : this.jie(String(e)));
case "object":
return this.handleObj(e, t)
}
},
"handleObj": function handleObj(e, t) {
var n = {};
for (var r in e) e.hasOwnProperty(r) && (n[r] = this.Enuu(e[r], t));
return n
},
"handleArr": function handleArr(e, t) {
var n = [];
return e.map(function(e) {
e = this.Enuu(e, t),
n.push(e)
}.bind(this)),
n
},
"jia": function jia(e) {
var t = [],
n = "",
r = "";
"string" == typeof e && (e = e.split(""));
for (var a = 0,
o = e.length; a < o; a++) n = e[a],
(r = encodeURIComponent(n)) == n && ("string" == typeof n && (r = n.charCodeAt().toString(16)), r = ("00" + r).slice( - 2)),
t.push(r);
return t.join("").replace(/%/g, "").toUpperCase()
},
"jie": function jie(e) {
for (var t = 0,
n = e.length,
r = "%"; t < n; t++) r += e[t],
t % 2 == 1 && (r += "%");
return r = r.substring(0, r.length - 1),
decodeURIComponent(r)
},
"versions": {
"alipay": !0
},
"getPcSize": function getPcSize() {
return window.screen.width + " * " + window.screen.height
},
"getVer": function getVer() {
var e, t = this.versions;
for (var n in t) t.hasOwnProperty(n) && t[n] && (e = n);
return e
},
"getNum": function getNum(e) {
switch (e) {
case "trident":
return 1;
case "presto":
return 2;
case "webKit":
return 3;
case "gecko":
return 4;
case "mobile":
return 5;
case "iOS":
return 6;
case "android":
return 7;
case "iPhone":
return 8;
case "iPad":
return 9;
case "webApp":
return 10;
case "weixin":
return 11;
default:
return 12
}
},
"detectOS": function detectOS() {
var e = navigator.userAgent,
t = "Win32" == navigator.platform || "Windows" == navigator.platform,
n = "Mac68K" == navigator.platform || "MacPPC" == navigator.platform || "Macintosh" == navigator.platform || "MacIntel" == navigator.platform;
if (n) return "Mac";
if ("X11" == navigator.platform && !t && !n) return "Unix";
if (String(navigator.platform).indexOf("Linux") > -1) return "Linux";
if (t) {
if (e.indexOf("Windows NT 5.0") > -1 || e.indexOf("Windows 2000") > -1) return "Win2000";
if (e.indexOf("Windows NT 5.1") > -1 || e.indexOf("Windows XP") > -1) return "WinXP";
if (e.indexOf("Windows NT 5.2") > -1 || e.indexOf("Windows 2003") > -1) return "Win2003";
if (e.indexOf("Windows NT 6.0") > -1 || e.indexOf("Windows Vista") > -1) return "WinVista";
if (e.indexOf("Windows NT 6.1") > -1 || e.indexOf("Windows 7") > -1) return "Win7"
}
return "other"
},
"getData": function getData(e, t) {
var n = {
"ver": e,
"headinfo": this.getPcSize() + "," + this.getNum(this.getVer()) + "," + this.detectOS(),
"plat": this.versions.iOS ? 1 : this.versions.android ? 2 : 3
};
return n.headinfo = this.Enuu(n.headinfo, !0),
void 0 !== t && t instanceof Object ? Object.assign(t, n) : n
}
}
var c = i.Enuu(Array.from(new Set(["window", "const", "Number", "StringBuffer", "var", "let", "number", "Array", "Function", "String", "public", "string", "Object", "document", "BOM", "Boolean", "Object", "let", "Array", "function", "encypt", "decrypt", "solid"])).filter((function(e, t) {
if (e.indexOf("s") > -1) return e
}))).map((function(e, t) {
return e.slice(Math.floor(e.length / 2), Math.floor(e.length / 2) + 1)
}))
var u="";
c.forEach((function(e, t) {
u += e
}))
var time=n = (new Date).getTime().toString()
function toUtf8(str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
var copy_iv=toUtf8(u+time)
const key = copy_iv
const iv = copy_iv
console.log(iv)
word='86mJKtRORKkWIWdxtvrrCsdK64Zc/D6JQh7ucTlwcuYSrbHeTsrJEqIDHq2VBwrYc+n4qIgcr0RcOn+K3OT62kNGlkUlx/ywR0S7FzUwnaZoffoqX5UefBRsygRxLpTV7NnnToC7jjyfdMlqxzjWcsJZiJrpNaxF+UhFUbHiHGyWCuI0Uw8/yjXj+g459esKVPvAsHH1cgqWi7IY0R53m85nhKTJea1EfkEGJIusLgV8bAcdcn2VlTTOQjwbJVgNbPeC01zI+KSjKLidricahGyQNKzIRoaRZ6f2LM9POcUx1AavcDlVpjvyhSr4TEnJvjUYmaaTSeH0oEnQOBWLkQV3WZBUvq9libXIxLlGzl8H7NnhnGmLdtmq7rZ4Odgvbs18qmlh8YMF39vUVbAfSRRPPoGvwVaHGZmb7F1q7JD5h+ZjQbH0IyFIFi2g9qbHOIy3Zeo/2P8zjWWwDbk1BAddGVCPF2Oa6NEGtS6CII6S2qvTJJx9FddigtQK6P+iynQh6BrYKQVDyqix5CLO/KFmq+L285vmMaxE/hjvPM4/wCpj5Q9jJpzfYgvomggjBwPp6yui3RdQ8TVJ7rH9g7seewrj/5FTfnuYUrn/2UBKJ+SOD2ktA2s12y8Ik4VCY87Y/TMO99O0xffcEfO9ILJpJXmarUqpSo7cAfcZycIcunYfFuyUqQTDOY34n0k1xUDaODz9vI41Kr2rw+0/Re1JAPWnLhqAcT+CH/26aMYjvZMdFXg8CgehuEXyyV2JXtagu7v/xDYAB62ReWfFkb2vWfqbeGVtscu/D8ZZdzdKz8Ff+8Dcs6s9ti+FfYcIQLY7UdfvFp4Dao4+Tbg6y65WC+TBc60sfP/Nq/6nXhKKB1aGyxeeu6HHqhNbV3WmSYL/3rGlSqgZnuAJzn1cdAD6VpboOOW2+rJ/wVvkL11mbjRmVyjhzS46ivqauEwcDnEbHUIiGVmVhFNtp1djuye73+OCgxTPhrHTEaZC7FUXPAQFL7Hv0TeX3JjK3uvPlLCFpvTInUqktkY/vOQsMdm02u2UGXy6JP75EL4AS5C/nUtPpdIb/5/Q5mrc66wX'
//解密方法
function Decrypt(word) {
let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
}
//加密方法
function Encrypt(word) {
let srcs = CryptoJS.enc.Utf8.parse(word);
let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
return encrypted.ciphertext.toString().toUpperCase();
}
var result=Decrypt(word)
console.log(result)
报错如下
C:\Users\Administrator\node_modules\crypto-js\core.js:523
throw new Error('Malformed UTF-8 data');
^
Error: Malformed UTF-8 data
at Object.stringify (C:\Users\Administrator\node_modules\[4mcrypto-js[24m\core.js:52
3:24)
at WordArray.init.toString (C:\Users\Administrator\node_modules\[4mcrypto-js[24m\cor
e.js:278:38)
at Decrypt (C:\Users\Administrator\Desktop\miniprogram\uu.js:171:29)
at Object.<anonymous> (C:\Users\Administrator\Desktop\miniprogram\uu.js:182:12)
[90m at Module._compile (internal/modules/cjs/loader.js:1158:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:1002:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:901:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:1
2)[39m
[90m at internal/main/run_main_module.js:18:47[39m
Error: Malformed UTF-8 data