You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
874 B

const aesJs = require('aes-js');
function _0x2925ac(x) {
var c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var e = "";
for (var W = 0; W < x; W++) {
e += c.charAt(Math.random(0, 62));
}
return e
}
function _0x5178e5(x) {
let _ = "";
for (let d = 0; d < x.length; d++) {
_ += String["fromCharCode"](x[d]);
}
return _
}
function aes_encrypt(key, str) {
let a = aesJs["utils"]["utf8"]["toBytes"](key)
, f = _0x2925ac(16)
, n = aesJs["utils"]["utf8"]["toBytes"](f)
, t = aesJs["utils"]["utf8"]["toBytes"](str);
t = aesJs.padding.pkcs7.pad(t);
const r = new aesJs.ModeOfOperation.cbc(a, n).encrypt(t);
const b = new Uint8Array(n["length"] + t["length"]);
b["set"](n, 0);
b["set"](r, 16);
return btoa(_0x5178e5(b))
}
module.exports = {aes_encrypt}