Added the decryption util

This commit is contained in:
Mathias Wagner 2023-01-15 18:37:38 +01:00
parent 3ce7b1941d
commit 2777aea903
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

8
src/utils/decryption.ts Normal file
View File

@ -0,0 +1,8 @@
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());