-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaesDecryptUtils.js
85 lines (79 loc) · 1.82 KB
/
aesDecryptUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const CryptoJS = require('crypto-js');
const aesKey = '3fp4xs922ouw5q72';
function p(e) {
var t = atob(e);
var i = new Uint8Array(t.length);
Array.prototype.forEach.call(t, function (e, t) {
i[t] = e.charCodeAt(0)
});
return i
}
function h(e) {
var t = new ArrayBuffer(e.length);
var i = new Uint8Array(t);
for (var n = 0, a = e.length; n < a; n++)
i[n] = e.charCodeAt(n);
return i
}
function m(e) {
var t = Array.prototype.map.call(e, function (e) {
return String.fromCharCode(e)
}).join("");
return btoa(t)
}
function p(e) {
var t = atob(e);
var i = new Uint8Array(t.length);
Array.prototype.forEach.call(t, function (e, t) {
i[t] = e.charCodeAt(0)
});
return i
}
function f(e) {
var t = [], i, n, a;
for (n = 0; n < e.length; ++n) {
i = e[n];
for (a = 3; a >= 0; --a)
t.push(i >> 8 * a & 255)
}
return t
}
function _(e) {
return String.fromCharCode.apply(null, e)
}
/**
* @param {*} e url
* @param {*} t key
* @returns
*/
function g(e, t) {
if (e) {
var i = window.location.protocol;
t = t.replace(/(^\/\/)|(^http:\/\/)|(^https:\/\/)/, i + "//");
var n = "token=" + encodeURIComponent(t) + "&t=" + (new Date).getTime();
if (e.indexOf("?") != -1)
return e + "&" + n;
else
return e + "?" + n
}
}
function decrupyAES(content) {
// 数据
var a = p(content);
var o = new Uint8Array(a.buffer, 0, 16);
// aes key
const n = CryptoJS.enc.Base64.parse(m(h(aesKey)));
o = CryptoJS.enc.Base64.parse(m(o));
let e = new Uint8Array(a.buffer, 16, a.length - 16);
e = CryptoJS.enc.Base64.parse(m(e));
var s = CryptoJS.AES.decrypt({
ciphertext: e
}, n, {
iv: o,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
const plaintext = _(f(s.words));
return JSON.parse(plaintext);
}
module.exports = { decrupyAES }