Skip to content

Instantly share code, notes, and snippets.

View hahuaz's full-sized avatar
🏠
Working from home

Hasan Biyik hahuaz

🏠
Working from home
View GitHub Profile
@hahuaz
hahuaz / encryption.js
Created October 16, 2022 13:19 — 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 bits (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', Buffer.from(ENCRYPTION_KEY), iv);