> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# AesGcm.encrypt

:::info
`AesGcm.encrypt` is a re-export of ox's [`AesGcm.encrypt`](https://oxlib.sh/api/AesGcm/encrypt). Refer to the ox documentation for the full reference.
:::

Encrypts data using AES-GCM.

## Imports

```ts
import { AesGcm } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { AesGcm, Hex } from 'viem/utils'

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'
```

## Definition

```ts
function encrypt<value, as>(
  value: value | Bytes.Bytes | Hex.Hex,
  key: CryptoKey,
  options?: encrypt.Options<as>,
): Promise<encrypt.ReturnType<as>>
```

## Parameters

### value

* **Type:** `value | Bytes.Bytes | Hex.Hex`

The data to encrypt.

### key

* **Type:** `CryptoKey`

The `CryptoKey` to use for encryption.

### options

* **Type:** `encrypt.Options<as>`
* **Optional**

Encryption options.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

The output format.

## Return Type

The encrypted data.

`Promise<encrypt.ReturnType<as>>`
