# AesGcm

Utilities & types for working with AES-GCM encryption. Internally uses the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API).

## Examples

Below are some examples demonstrating common usages of the `AesGcm` module:

* [Encrypting Data](#encrypting-data)

* [Decrypting Data](#decrypting-data)

### Encrypting Data

Data can be encrypted using [`AesGcm.encrypt`](/api/AesGcm/encrypt):

```ts twoslash
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) // [!code focus]
// @log: '0x5e257b25bcf53d5431e54e5a68ca0138306d31bb6154f35a97bb8ea18111e7d82bcf619d3c76c4650688bc5310eed80b8fc86d1e3e'
```

### Decrypting Data

Data can be decrypted using [`AesGcm.decrypt`](/api/AesGcm/decrypt):

```ts twoslash
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) // [!code focus]
// @log: Hex.fromString('i am a secret message')
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`AesGcm.decrypt`](/api/AesGcm/decrypt) | Decrypts encrypted data using AES-GCM. |
| [`AesGcm.encrypt`](/api/AesGcm/encrypt) | Encrypts data using AES-GCM. |
| [`AesGcm.getKey`](/api/AesGcm/getKey) | Derives an AES-GCM key from a password using PBKDF2. |
| [`AesGcm.randomSalt`](/api/AesGcm/randomSalt) | Generates a random salt of the specified size. |
