Function: encryptData()
encryptData(Defined in: crypto.ts:89 Encrypt a UTF-8 string with AES-256-GCM authenticated encryption. Each call generates a fresh random salt and IV — the same plaintext encrypted twice with the sameplaintext,encryptionKey):Promise<string>
encryptionKey produces different
ciphertexts, which is the property you want for at-rest encryption.
Output layout (base64-encoded): salt(32) | iv(16) | authTag(16) | ciphertext(*).
The companion decryptData understands this layout.
Parameters
plaintext
string
UTF-8 string to encrypt.
encryptionKey
string
Caller-supplied secret. Treated as a password
and stretched into a 256-bit AES key via scrypt; can be any length,
though a high-entropy secret (≥ 32 bytes) is strongly preferred.
Returns
Promise<string>
A self-contained base64 string. Store or transmit verbatim;
the salt/IV are recovered on decryption.
Throws
From the underlying Node crypto primitives ifencryptionKey
is empty or scrypt fails.