Skip to content

Instantly share code, notes, and snippets.

View DavidCorral94's full-sized avatar
🤔
What's going on?

David Corral Plaza DavidCorral94

🤔
What's going on?
View GitHub Profile
@vlucas
vlucas / encryption.ts
Last active May 3, 2025 05:24
Stronger Encryption and Decryption in Node.js
import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
const ENCRYPTION_KEY: string = process.env.ENCRYPTION_KEY || ""; // Must be 256 bits (32 characters)
const IV_LENGTH: number = 16; // For AES, this is always 16
/**
* Will generate valid encryption keys for use
* Not used in the code below, but generate one and store it in ENV for your own purposes
*/
export function keyGen() {