Encrypt
Encrypts a text using AES-GCM encryption algorithm.
| Category | Functions |
| Author | Pol Gubau |
| Since | 1.0.1 |
| Last Updated | 2025-03-15 |
| Type | Async |
| Compatibility | Browser |
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
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| text | string | null | Yes | The text to encrypt. |
| key | string | null | Yes | The 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