@holographxyz/cli
Version:
Holograph operator CLI
32 lines (31 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const crypto = tslib_1.__importStar(require("node:crypto"));
const encryptionType = 'aes-256-cbc';
const encryptionEncoding = 'base64';
const bufferEncryption = 'utf8';
class AesEncryption {
AesKey;
AesIV;
constructor(key, iv) {
this.AesKey = key;
this.AesIV = iv;
}
encrypt(val) {
const key = Buffer.concat([Buffer.from(this.AesKey, bufferEncryption)], 32);
const iv = Buffer.concat([Buffer.from(this.AesIV, bufferEncryption)], 16);
const cipher = crypto.createCipheriv(encryptionType, key, iv);
let encrypted = cipher.update(val, bufferEncryption, encryptionEncoding);
encrypted += cipher.final(encryptionEncoding);
return encrypted;
}
decrypt(base64String) {
const buff = Buffer.from(base64String, encryptionEncoding);
const key = Buffer.concat([Buffer.from(this.AesKey, bufferEncryption)], 32);
const iv = Buffer.concat([Buffer.from(this.AesIV, bufferEncryption)], 16);
const decipher = crypto.createDecipheriv(encryptionType, key, iv);
return decipher.update(buff).toString() + decipher.final().toString();
}
}
exports.default = AesEncryption;