Encrypt and Decrypt in NodeJS

1 · Alex Adam · Aug. 21, 2021, 10:27 a.m.
How to encrypt textCreate a file named encdec.js and paste:const crypto = require("crypto")const encrypt = (plainText, password) => { try { const iv = crypto.randomBytes(16); const key = crypto.createHash('sha256').update(password).digest('base64').substr(0, 32); const cipher = crypto.createCipheriv('aes-256-cbc', key, iv); let encrypted = cipher.update(plainText); encrypted = Buffer.concat([encrypted, cipher.final()]) return iv.toString('hex') + ':' + encrypted.toString('hex'...