nodejs encryption 128bit

The solution for “nodejs encryption 128bit” can be found here. The following code will assist you in solving the problem.

import * as crypto from “crypto”;

const algorithm:string = ‘aes-128-ecb’;
const key:Buffer = crypto.randomBytes(16);

// Encryption
const plaintextEnc:Buffer = Buffer.from(‘0123456789012345’);
const cipherEnc:crypto.Cipher = crypto.createCipheriv(algorithm, key, null);
cipherEnc.setAutoPadding(false);
const ciphertext:Buffer = Buffer.concat([cipherEnc.update(plaintextEnc), cipherEnc.final()]);
console.log(ciphertext.toString(‘hex’));

// Decryption
const cipherDec:crypto.Decipher = crypto.createDecipheriv(algorithm, key, null);
cipherDec.setAutoPadding(false);
const plaintextDec:Buffer = Buffer.concat([cipherDec.update(ciphertext), cipherDec.final()]);
console.log(plaintextDec.toString(‘hex’));

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in