import { scryptSync, createCipheriv, createDecipheriv } from 'crypto' const iv = Buffer.alloc(16, 0) const algorithm = 'aes-256-cbc' const key = scryptSync(process.env.SECRET as string, process.env.SALT, 32) export function encode(raw: string) { const cipher = createCipheriv(algorithm, key, iv) const encrypted = cipher.update(raw, 'utf8', 'base64') + cipher.final('base64') return encrypted } export async function decode(encrypted: string) { const deciper = createDecipheriv(algorithm, key, iv) const decrypted = deciper.update(encrypted, 'base64', 'utf8') + deciper.final('utf8') return decrypted }
Node crypto
Creator
Creator
Seonglae ChoCreated
Created
2023 Nov 28 12:9Editor
Editor
Seonglae ChoEdited
Edited
2023 Nov 28 12:10Refs
Refs

