Not Exported
Encrypted data with authentication tag
Initialization vector in hex format
Decrypted text content
function decrypt(encryptedData: string, iv: string): string {
const key = getEncryptionKey();
const ivBuffer = Buffer.from(iv, "hex");
// Validate encrypted data
if (!encryptedData) {
throw new Error("Encrypted data is undefined or empty");
}
// Extract data and authentication tag
const encryptedParts = encryptedData.split(":");
const encrypted = encryptedParts[0];
const authTag = Buffer.from(encryptedParts[1], "hex");
const decipher = crypto.createDecipheriv(ALGORITHM, key, ivBuffer);
decipher.setAuthTag(authTag);
let decrypted = decipher.update(encrypted, "hex", "utf8");
decrypted += decipher.final("utf8");
return decrypted;
}
Decrypts previously encrypted data