From b45b6e069293f7a001d57a4d1c73f6eb5530c2d5 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 5 Oct 2024 15:48:11 +0530 Subject: [PATCH] feat: use process.env --- server/src/utils/auth.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index 9b6a37f1..9f43759d 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -23,8 +23,8 @@ export const comparePassword = (password: string, hash: string): Promise { - const iv = crypto.randomBytes(IV_LENGTH); - const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), iv); + const iv = crypto.randomBytes(process.env.IV_LENGTH); + const cipher = crypto.createCipheriv(process.env.ALGORITHM, Buffer.from(process.env.ENCRYPTION_KEY), iv); let encrypted = cipher.update(text, 'utf8', 'hex'); encrypted += cipher.final('hex'); return `${iv.toString('hex')}:${encrypted}`; @@ -32,7 +32,7 @@ const encrypt = (text: string): string => { const decrypt = (encryptedText: string): string => { const [iv, encrypted] = encryptedText.split(':'); - const decipher = crypto.createDecipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), Buffer.from(iv, 'hex')); + const decipher = crypto.createDecipheriv(process.env.ALGORITHM, Buffer.from(process.env.ENCRYPTION_KEY), Buffer.from(iv, 'hex')); let decrypted = decipher.update(encrypted, 'hex', 'utf8'); decrypted += decipher.final('utf8'); return decrypted;