Encrypt

Encrypts a text using AES-GCM encryption algorithm.

CategoryFunctions
AuthorPol Gubau
Since1.0.1
Last Updated2025-03-15
TypeAsync
CompatibilityBrowser

Example

  • Input

    await encrypt('Hello, world!', 'your-32-character-key')

    Output:

    encrypted text in base64

Return

Returns the encrypted text in base64 format.

Type: string

Props

NameTypeDefaultRequiredDescription
textstringnullYesThe text to encrypt.
keystringnullYesThe encryption key (must be at least 32 characters long).

Notes

This function uses the AES-GCM encryption algorithm for encrypting text.

Errors

Throws an error if the key is less than 32 characters.

Tags

  • encryption
  • AES-GCM
  • security

Related