> For the complete documentation index, see [llms.txt](https://doc.duaer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.duaer.com/zh/hosting/configuration/configuration-examples/encryption-key.md).

# 为 Duaer 设置自定义加密密钥

为 Duaer 设置自定义加密密钥，用于安全加密凭证。
## 用环境变量指定密钥

Duaer 首次启动会自动生成随机加密密钥，并保存在实例数据目录。若设置文件里还没有密钥，可设置环境变量，让 Duaer 使用你的自定义密钥，而不是再生成一把。

队列模式下，所有 worker 都必须设置该环境变量。

```
export DUAER_ENCRYPTION_KEY=<SOME RANDOM STRING>
```

更多说明见 [环境变量](/zh/hosting/configuration/environment-variables.md)。
## Questions

### 怎么为 Duaer 设置自定义加密密钥？

在环境里执行 export DUAER_ENCRYPTION_KEY=<SOME RANDOM STRING>，或写进 .env / 容器注入后重启。值要足够长的随机串。每个实例用自己的值；生产与开发不要共用。队列模式的所有 worker 也要设同一把。

