cea-core
Version:
basic cea api
24 lines (23 loc) • 725 B
JavaScript
import crypto from "node:crypto";
export default class AES {
constructor(pwd, key) {
this.pwd = pwd;
this.key = key;
}
encrypt() {
const { key, pwd } = this;
const rs = AES.randomString;
const data = rs(64) + pwd;
const algorithm = "aes-128-cbc";
const iv = Buffer.alloc(16, 0);
const cipher = crypto.createCipheriv(algorithm, key, iv);
let en = cipher.update(data, "utf8", "base64");
en += cipher.final("base64");
return en;
}
static randomString(len) {
const str = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
return Array(len).fill(null).reduce((s = "") => s += str.charAt(Math.floor(Math.random() * 48)), "");
}
}
//# sourceMappingURL=encrypt.js.map