> ## 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

> Decrypts Base64 ciphertext with a Base64-decoded key and required Base64 IV using AES CBC or ECB.

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

  ## Arguments

  <ParamField path={"data"} type={"string"} required>
    Base64 ciphertext decoded before decryption.
  </ParamField>

  <ParamField path={"key"} type={"string"} required>
    Base64 key decoded before it is passed to AES.
  </ParamField>

  <ParamField path={"iv"} type={"string"} required>
    Base64 IV decoded before mode handling. This argument is required, including for ECB.
  </ParamField>

  <ParamField path={"mode"} type={"\"CBC\" | \"ECB\" | \"AES-CBC\" | \"AES-ECB\""}>
    AES mode. The AES- prefix is removed when present. Defaults to AES-CBC.
  </ParamField>

  ## Returns

  <ResponseField name={"plaintext"} type={"string"}>
    Plaintext bytes returned as a Lua string.
  </ResponseField>

  ## Example

  Decrypt ciphertext returned by crypt.encrypt using the returned IV.

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