# 生成密钥和证书

要启用 UEFI 安全启动，请生成一对用于签名和身份验证的密钥和证书。

密钥生成支持以下算法：

- RSA 2048/4096 与 SHA-256/SHA384 哈希算法
- ECDSA secp256r1/secp384r1

以下过程提供了以 RSA 2048 和 SHA-256 为例生成密钥和证书的说明。

Note

- 创建一个目录并在同一位置执行命令以在 Linux 计算机上执行这些步骤。
- 关于 ECC，将 `rsa:2048` 替换为 `ec:secp384r1` 或 `ec:secp256r1`。关于 SHA384，请在以下命令中将 `-sha256` 替换为 `-sha384`。

## 生成 UID

您可以生成 GUID 并创建三个新密钥，其中包含 CRT/PEM 格式的自签名证书和 `.key` 格式的密钥：

GUID使用 `uuidgen` 生成签名所有者 GUID：

uuidgen --random > GUID.txt
    Copy to clipboard

## 创建 PK 密钥

1. 创建 PK 密钥对 (RSA-2048) 和证书：

openssl req -new -x509 -newkey rsa:2048 -subj "/CN=Custom PK/" -keyout PK.key -out PK.crt -days 3650 -nodes -sha256
        Copy to clipboard
2. 将 `.crt` 文件转换为 `.cer` 文件：

openssl x509 -outform der -in PK.crt -out PK.cer
        Copy to clipboard
3. 将 `.crt` 文件转换为 `.esl` 文件：

cert-to-efi-sig-list -g "$(< GUID.txt)" PK.crt PK.esl
        Copy to clipboard
4. 使用 `.crt`、`.esl` 和 `.key` 文件签署并生成 `.auth` 文件：

sign-efi-sig-list -k PK.key -c PK.crt PK PK.esl PK.auth
        Copy to clipboard

## 创建 KEK 密钥

1. 创建 KEK 密钥对 (RSA-2048) 和证书：

openssl req -new -x509 -newkey rsa:2048 -subj "/CN=Custom KEK/" -keyout KEK.key -out KEK.crt -days 3650 -nodes -sha256
        Copy to clipboard
2. 将 `.crt` 文件转换为 `.cer` 文件：

openssl x509 -outform der -in KEK.crt -out KEK.cer
        Copy to clipboard
3. 将 `.crt` 文件转换为 `.esl` 文件：

cert-to-efi-sig-list -g "$(< GUID.txt)" KEK.crt KEK.esl
        Copy to clipboard
4. 使用 `.crt`、`.esl` 和 `.key` 文件签署并生成 `.auth` 文件：

sign-efi-sig-list -k PK.key -c PK.crt KEK KEK.esl KEK.auth
        Copy to clipboard

## 创建 dB 密钥

1. 创建 dB 密钥对 (RSA-2048) 和证书：

openssl req -new -x509 -newkey rsa:2048 -subj "/CN=Custom DB Signing Key 1/" -keyout db.key -out db.crt -days 3650 -nodes -sha256
        Copy to clipboard
2. 将 `.crt` 文件转换为 `.cer` 文件：

openssl x509 -outform der -in db.crt -out db.cer
        Copy to clipboard
3. 将 `.crt` 文件转换为 `.esl` 文件：

cert-to-efi-sig-list -g "$(< GUID.txt)" db.crt db.esl
        Copy to clipboard
4. 使用 `.crt`、`.esl` 和 `.key` 文件签署并生成 `.auth` 文件：

sign-efi-sig-list -k KEK.key -c KEK.crt db db.esl db.auth
        Copy to clipboard

## 后续步骤

- 要使系统在启动期间验证并仅加载受信任的软件，请参阅[签名镜像并将 (.auth) 密钥/签名文件复制到 EFI 分区](https://docs.qualcomm.com/doc/80-70018-11SC/topic/sign-images-and-copy-auth-key-signed-files-to-efi-partition.html#sign-images-and-copy-auth-key-signed-files-to-efi-partition)。
- 要确保通过 systemd-boot 菜单正确应用和维护安全启动设置，请参阅[从 systemd-boot 菜单启用 UEFI 安全启动](https://docs.qualcomm.com/doc/80-70018-11SC/topic/enable-uefi-secure-boot-from-systemd-boot-menu.html#enable-uefi-secure-boot-from-systemd-boot-menu)。

Last Published: Apr 29, 2025

[Previous Topic
启用 UEFI 安全启动](https://docs.qualcomm.com/bundle/publicresource/80-70018-11SC/topics/enable-uefi-secure-boot.md) [Next Topic
对镜像进行签名并将 (.auth) 密钥/签名文件复制到 EFI 分区](https://docs.qualcomm.com/bundle/publicresource/80-70018-11SC/topics/sign-images-and-copy-auth-key-signed-files-to-efi-partition.md)