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

# crypt.decrypt

> 使用从 Base64 解码的 key 和必需的 Base64 IV，通过 AES CBC 或 ECB 解密 Base64 ciphertext。

<div className="real-function-page">
  ```lua theme={null}
  crypt.decrypt(data: string, key: string, iv: string, mode?: "CBC" | "ECB" | "AES-CBC" | "AES-ECB"): string
  ```

  ## 参数

  <ParamField path={"data"} type={"string"} required>
    解密前会被解码的 Base64 ciphertext。
  </ParamField>

  <ParamField path={"key"} type={"string"} required>
    传递给 AES 前会被解码的 Base64 key。
  </ParamField>

  <ParamField path={"iv"} type={"string"} required>
    处理 mode 前会被解码的 Base64 IV。此参数是必需的，包括 ECB。
  </ParamField>

  <ParamField path={"mode"} type={"\"CBC\" | \"ECB\" | \"AES-CBC\" | \"AES-ECB\""}>
    AES mode。如果存在 AES- prefix，会将其移除。默认值是 AES-CBC。
  </ParamField>

  ## 返回值

  <ResponseField name={"plaintext"} type={"string"}>
    以 Lua string 返回的 plaintext 字节。
  </ResponseField>

  ## 示例

  使用返回的 IV 解密 crypt.encrypt 返回的 ciphertext。

  ```lua theme={null}
  local key = crypt.generatekey()
  local ciphertext, iv = crypt.encrypt("hello world", key)

  local plaintext = crypt.decrypt(ciphertext, key, iv)

  print(plaintext)
  ```
</div>
