feat: decryption

This commit is contained in:
karishmas6
2024-10-05 15:42:32 +05:30
parent 573541e21a
commit f61063cee8

View File

@@ -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;
};