![Shortest and simplest string encryption / decryption with AES-256 in Node.JS](/content/images/size/w720/2023/11/Firefly-copy-paste-ready-encryption-decryption-computer-program-41387.jpg)
Shortest and simplest string encryption / decryption with AES-256 in Node.JS
Copy and paste the following code in a .js file, then run it.
// Libraries
const crypto = require('crypto');
// Constants
const OUTPUT_FORMAT = "hex";
const ALGORITHM = "aes256";
const KEY = "012345ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const IV = "ABCDEF0123456789";
// Implementations
function encrypt(message) {
let cipher = crypto.createCipheriv(
ALGORITHM,
Buffer.from(KEY),
Buffer.from(IV)
);
return (Buffer.concat(