Backend/src/utils/decryption.ts

8 lines
431 B
TypeScript

import fieldEncryption from "mongoose-field-encryption";
import crypto from "crypto";
const createHash = () => crypto.createHash("sha256").update(process.env.ENC_KEY || "").digest("hex").substring(0, 32);
export const encryptClearField = (text: string) => fieldEncryption.encrypt(text, createHash(), () => process.env.SIG_KEY);
export const decryptField = (encrypted: string) => fieldEncryption.decrypt(encrypted, createHash());