From 2777aea9034abd347e282307488bea51896f3a2c Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 15 Jan 2023 18:37:38 +0100 Subject: [PATCH] Added the decryption util --- src/utils/decryption.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/utils/decryption.ts diff --git a/src/utils/decryption.ts b/src/utils/decryption.ts new file mode 100644 index 0000000..df38fd4 --- /dev/null +++ b/src/utils/decryption.ts @@ -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()); \ No newline at end of file