Encrypt a string with a secret using AES-256-GCM.
The string is first compressed using deflate, then encrypted with a random IV and salt. The result is encoded as URL-safe Base64.
The plaintext to encrypt
The secret key for encryption
URL-safe Base64 encoded ciphertext (includes salt, IV, and auth tag)
const encrypted = encrypt('Secret message', 'mySecret123')console.log(encrypted) Copy
const encrypted = encrypt('Secret message', 'mySecret123')console.log(encrypted)
Encrypt a string with a secret using AES-256-GCM.
The string is first compressed using deflate, then encrypted with a random IV and salt. The result is encoded as URL-safe Base64.