Skip to content

Instantly share code, notes, and snippets.

View drscottlobo's full-sized avatar

Scott Wolf drscottlobo

View GitHub Profile
@drscottlobo
drscottlobo / encryption.js
Created May 25, 2019 17:01 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bytes (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);