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