From f61063cee83c8b18043530669ea7808a4baf7359 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 5 Oct 2024 15:42:32 +0530 Subject: [PATCH] feat: decryption --- server/src/utils/auth.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index 2468fe53..9b6a37f1 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -28,4 +28,12 @@ const encrypt = (text: string): string => { let encrypted = cipher.update(text, 'utf8', 'hex'); encrypted += cipher.final('hex'); return `${iv.toString('hex')}:${encrypted}`; +}; + +const decrypt = (encryptedText: string): string => { + const [iv, encrypted] = encryptedText.split(':'); + const decipher = crypto.createDecipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), Buffer.from(iv, 'hex')); + let decrypted = decipher.update(encrypted, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; }; \ No newline at end of file