AesGcm
Utilities & types for working with AES-GCM encryption. Internally uses the Web Crypto API.
Examples
Below are some examples demonstrating common usages of the AesGcm
module:
Encrypting Data
Data can be encrypted using AesGcm.encrypt
:
import { AesGcm, Hex } from 'ox'
const key = await AesGcm.getKey({ password: 'qwerty' })
const secret = Hex.fromString('i am a secret message')
const encrypted = await AesGcm.encrypt(secret, key)
'0x5e257b25bcf53d5431e54e5a68ca0138306d31bb6154f35a97bb8ea18111e7d82bcf619d3c76c4650688bc5310eed80b8fc86d1e3e'
Decrypting Data
Data can be decrypted using AesGcm.decrypt
:
import { AesGcm, Hex } from 'ox'
const key = await AesGcm.getKey({ password: 'qwerty' })
const encrypted = await AesGcm.encrypt(Hex.fromString('i am a secret message'), key)
const decrypted = await AesGcm.decrypt(encrypted, key)
Hex.fromString('i am a secret message')
Functions
Name | Description |
---|---|
AesGcm.decrypt | Decrypts encrypted data using AES-GCM. |
AesGcm.encrypt | Encrypts data using AES-GCM. |
AesGcm.getKey | Derives an AES-GCM key from a password using PBKDF2. |
AesGcm.randomSalt | Generates a random salt of the specified size. |