Tag Archives: Decrypt

Encrypt and Decrypt in NodeJS – Node Dev Feed

Encrypt and Decrypt in NodeJS How to encrypt text Create 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’) +…

Read More