第一步:在浏览器(检查-源代码-代码段-右键运行)中执行1.js 获取key和staticchars给2.js用
// en.oal.1.js//本地加密,F12把这个打印出来的更新到en.oal.2.js的key和staticchars
const array = []
array[13332] = 'SHA256'
array[332] = 'enc'
array[983] = 'Base64'
const string = array.join('|')
let staticchars = getKey()
let key = encode(string, staticchars)
console.log('key', key)
console.log('staticchars', staticchars)
//获取62个字符的随机顺序
function getKey() {
let key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
key.sort(function () {
return (0.5 - Math.random());
});
return key.join('')
}
function encode(_str, staticchars) {
let encodechars = "";
for (let i = 0; i < _str.length; i++) {
let num0 = staticchars.indexOf(_str[i]);
let code = num0 === -1 ? _str[i] : staticchars[(num0 + 3) % 62];
let num1 = parseInt(String(Math.random() * 62), 10);
let num2 = parseInt(String(Math.random() * 62), 10);
encodechars += staticchars[num1] + code + staticchars[num2];
}
return encodechars;
}
第二步:将key和staticchars的值替换,把整个文件代码进行混淆生产3.js
//en.oal.2.js
//服务器加密的原始代码,
//去https://www.lddgo.net/encrypt/js混淆下变成3
//
const rhz = (i) => {
const key = `l1jEcK0Ta8xzm7xGwWv|9W0lLzuqMgS|ecqCPAWwDOz0O9wzQQN`
let s = decode(key).split('|')
return s[i]
function decode(_str) {
const staticchars = '0NduU8KfJ6PiwInRmz43EQoYypOSV91t2bXxajvAZsTCDHhWc5BM7qGklLgerF'
let decodechars = "";
for (let i = 1; i < _str.length;) {
let num0 = staticchars.indexOf(_str[i]);
let code
if (num0 == -1) {
code = _str[i];
} else {
code = staticchars[(num0 + 59) % 62];
}
decodechars += code;
i = i + 3;
}
return decodechars;
}
}
第三步:把3.js文件在项目中引用,有个全局变量叫rhz,rhz(13332)对应就是SHA256字符串