function test() {
const key = randomBytes(32);
const iv = randomBytes(16);
const cipher = createCipheriv("aes-256-cbc", key, iv);
const decipher = createDecipheriv("aes-256-cbc", key, iv);
const data = "Hello World";
const encrypted =
cipher.update(data, "utf8", "base64") + cipher.final("base64");
const decrypted =
decipher.update(encrypted, "base64", "utf8") + decipher.final("utf8");
console.dir({ data, encrypted, decrypted });
}
test();
function test() {
const key = randomBytes(32);
const iv = randomBytes(16);
const cipher = createCipheriv("aes-256-cbc", key, iv);
const decipher = createDecipheriv("aes-256-cbc", key, iv);
const data = "Hello World";
const encrypted =
cipher.update(data, "utf8", "base64") + cipher.final("base64");
const decrypted =
decipher.update(encrypted, "base64", "utf8") + decipher.final("utf8");
console.dir({ data, encrypted, decrypted });
}
test();