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

# Decrypt webhook

These are the requirements and steps for decrypting a webhook.

```json Structure of the message that our webhooks send theme={null}
{
  "data": "bea4343c5d815cba55c6e1bcb835bcbea43432abc014f7b48a63....",
  "iv": "1aa8ebae81e116621251993df3b155d4"
}
```

<Note>Secret is used to decrypt the webhook payload.</Note>

<Note>
  Standard decryption for aes-256-cbc using the data, the iv, and the secret
  returned during the webhook registration.
</Note>

<Steps>
  <Step title="Converts the hexadecimal IV to a byte buffer">
    * \[Recommendation] Check if the key length is 32 bytes, which is the required size for the AES-256 encryption algorithm.

    ```typescript TypeScript Example theme={null}
    const key = Buffer.from(WEBHOOK_SHARED_SECRET_ENCRYPTION_KEY, "base64");
    if (key.length !== 32) {
      throw new Error("Encryption key must be 256 bits (32 bytes)");
    }
    ```

    * Converts the hexadecimal IV to a byte buffer.

    ```typescript TypeScript Example theme={null}
    const ivBuffer = Buffer.from(iv, "hex");
    ```
  </Step>

  <Step title="Decryption">
    * Creates a decryptor object using the AES-256 algorithm in CBC (Cipher Block Chaining) mode, the key and the IV.

    ```typescript TypeScript Example theme={null}
    const decipher = crypto.createDecipheriv("aes-256-cbc", key, ivBuffer);
    ```

    * Start decrypting the data and store the result.

    ```typescript TypeScript Example theme={null}
    let decrypted = decipher.update(data, "hex", "utf8");
    decrypted += decipher.final("utf8");
    ```
  </Step>
</Steps>

<Note>
  **Disclaimer**: All technical documentation is subject to the terms and
  conditions, which apply supplementarily and take precedence over the
  documentation.
</Note>
