> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# crypt.decrypt

Decrypts an AES-encrypted string using the matching key, IV, and mode.

```luau theme={null}
crypt.decrypt(data: string, key: string, iv: string, mode: string?): string
```

`key` and `iv` must match the values used during encryption - implying same 32-byte base64 key, same 16-byte base64 IV.

`mode` defaults to `"CBC"` if omitted. <br /> Accepts the same set as `crypt.encrypt()`: `"CBC"`, `"ECB"`, `"CTR"`, `"CFB"`, `"OFB"`, `"GCM"`. <br /> [Learn more here](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation).

Most commonly used to recover payloads sent via `crypt.encrypt()`.

## Parameters

| Parameter | Type      | Description                                                                       |
| --------- | --------- | --------------------------------------------------------------------------------- |
| `data`    | `string`  | The base64-encoded ciphertext to decrypt.                                         |
| `key`     | `string`  | Base64-encoded 32-byte AES key. Must match the key used to encrypt.               |
| `iv`      | `string`  | Base64-encoded 16-byte IV. Must match the IV used to encrypt.                     |
| `mode`    | `string?` | One of `"CBC"`, `"ECB"`, `"CTR"`, `"CFB"`, `"OFB"`, `"GCM"`. Defaults to `"CBC"`. |

## Returns

`string` - the recovered plaintext.

## Example

Read a token cached to disk by `crypt.encrypt` and recover the plaintext.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  local decrypt = crypt.decrypt("Hello, world!", "test", "test", "test")
  =======
  -- crypt.decrypt(data: string, key: string, iv: string, mode: string?): string
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local KEY = "your-base64-key" -- same key used to encrypt

  local blob = readfile("sensitive-data.cache")
  local cipher, iv = blob:match("(.-)|(.+)")

  local token = crypt.decrypt(cipher, KEY, iv)
  print(token) --> "LIC-A1B2C3D4-EXP-2026"
  ```
</CodeGroup>

<Tip>
  Ensure the key and IV lengths match the expectations of the selected cipher mode.
</Tip>
