Skip to content

Instantly share code, notes, and snippets.

View jtmthf's full-sized avatar

Jack Moore jtmthf

View GitHub Profile
@jtmthf
jtmthf / encrypt_decrypt.ts
Last active April 18, 2021 13:20 — forked from csanz/encrypt_decrypt.js
Simple String Encryption & Decryption with Node.js
import {createCipheriv, createDecipheriv} from "crypto";
const ALGORITHM = "aes-256-cbc";
const ENCODING = "utf8";
const DEFAULT_INITIALIZATION_VECTOR = "0";
const DEFAULT_SYMMETRIC_KEY = "d6F3Efeq";
function encrypt(value: string, key = DEFAULT_SYMMETRIC_KEY, iv = DEFAULT_INITIALIZATION_VECTOR) {
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
let crypted = cipher.update(value, ENCODING, "base64");