Not Exported
Plain text content to encrypt
Object containing encrypted data and initialization vector
function encrypt(text: string): { encryptedData: string; iv: string } {
const key = getEncryptionKey();
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
let encrypted = cipher.update(text, "utf8", "hex");
encrypted += cipher.final("hex");
// Append authentication tag to encrypted data
return {
encryptedData: encrypted + ":" + cipher.getAuthTag().toString("hex"),
iv: iv.toString("hex"),
};
}
Encrypts text using AES-256-GCM