> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/wemreference/functions/security/aesiv.md).

# AesIv

{% hint style="info" %}
Generates a random Initialization Vector (IV) for use with `aesencrypt()` and `aesdecrypt()`.
{% endhint %}

{% hint style="success" %}
Returns a <mark style="color:$success;">`plaintext`</mark>
{% endhint %}

`aesiv()` produces a cryptographically random 16-byte (128-bit) Initialization Vector, returned as a base64-encoded text string. The IV ensures that identical plaintexts encrypted with the same key produce different ciphertexts, preventing pattern analysis attacks.

Together with `aeskey()`, the IV forms the two required inputs to the AES encryption system. The IV does not need to be secret, it is safe to store and transmit alongside the ciphertext, but it must be unique per encryption operation and must be passed to `aesdecrypt()` unchanged.

### Syntax

<details>

<summary>AesIV()</summary>

`AesIV()`

⇒ "d7133817026e13e7839df65dd7130eb7"

</details>

<details>

<summary>AesIV() use for MFA</summary>

The `AesIV()` result is assigned to the field `[Users.MfaVector]`  in a previous assignment. \
`AesEncrypt()` is used to encrypt and assign the users secret to the `[Users.MFASecret]` field

```
AesEncrypt([Authentication.Mfa.TempmfaSecret]
                    ,[System.MfaKey]
                    ,[Users.Mfa.MfaVector])
```

The result is now together with the `vector` stored in the Users database list, and can then together be used to for the creation of 2fa codes. [You can find more information about 2fa here.](/platform/wemtipsandtricks/security/2fa-with-totp.md)

</details>

### Parameters

| Parameter | Type | Description                        |
| --------- | ---- | ---------------------------------- |
| —         |      | This function takes no parameters. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.wem.io/platform/wemreference/functions/security/aesiv.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
