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

> 使用 random byte generator 生成 32 个随机 raw bytes，并以 Base64-encoded Lua string 返回。

<div className="real-function-page">
  ```lua theme={null}
  crypt.generatekey(): string
  ```

  ## 返回值

  <ResponseField name={"key"} type={"string"}>
    生成的 32 个 raw bytes 的 Base64 encoding。返回的 string 不是 32 个字符长。
  </ResponseField>

  ## 示例

  生成 Base64 key，并解码它以检查 raw bytes 数量。

  ```lua theme={null}
  local key = crypt.generatekey()
  local raw = base64_decode(key)

  local ciphertext, iv = crypt.encrypt("hello world", key)

  print(key)
  print(#raw)
  print(ciphertext, iv)
  ```
</div>
