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

> Lua string byte degerlerini Base64 decode edilmis key ile AES CBC, ECB veya CTR kullanarak encrypt eder, sonra Base64 ciphertext ve IV sonucunu dondurur.

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

  ## Argümanlar

  <ParamField path={"data"} type={"string"} required>
    Lua string icinden okunan plaintext byte degerleri.
  </ParamField>

  <ParamField path={"key"} type={"string"} required>
    AES icine aktarilmadan once decode edilen Base64 key.
  </ParamField>

  <ParamField path={"iv"} type={"string"}>
    CBC veya CTR icin optional Base64 IV. CBC veya CTR icin verilmezse AES block size boyutunda yeni bir IV uretilir.
  </ParamField>

  <ParamField path={"mode"} type={"\"CBC\" | \"ECB\" | \"CTR\" | \"AES-CBC\" | \"AES-ECB\" | \"AES-CTR\""}>
    AES mode. Varsa AES- prefix kaldirilir. Varsayilan deger AES-CBC. CBC ve ECB crypto library DEFAULT\_PADDING kullanir; CTR padding kullanmaz.
  </ParamField>

  ## Dönüşler

  <ResponseField name={"ciphertext"} type={"string"}>
    Base64-encoded ciphertext.
  </ResponseField>

  <ResponseField name={"initializationVector"} type={"string | nil"}>
    CBC ve CTR icin Base64-encoded IV; ECB icin nil.
  </ResponseField>

  ## Örnek

  Bir Lua string degerini encrypt et ve dondurulen ciphertext degerini dondurulen IV ile decrypt et.

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

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

  print(ciphertext)
  print(iv)
  print(plaintext)
  ```
</div>
