Simple aes-256-cbc encryption tools
npm install aes256cbc-enc
# or
yarn add aes256cbc-enc
// in common JS
const { Aes256Cbc, generateKey } = require("aes256cbc-enc");
// in typescript
import { Aes256Cbc, generateKey } from "aes256cbc-enc";
// generate random key
const key = generateKey();
// create new instance
const aes = new Aes256Cbc({
key: "", // 64 character string hex
});
// or if you want generate from string
const aes = new Aes256Cbc({
rawKey: "", // any string
});
// print current key
const currKey = aes.getCurrentKey();
// encrypt and decrypt
const plainText = "test123";
const encryptedText = aes.encrypt(plainText);
const decryptedText = aes.decrypt(encryptedText);
console.log({ encryptedText, decryptedText });