# 生成密钥和证书

Source: [https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html](https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html)

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

密钥生成支持以下算法：

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

以下过程提供了以 RSA 2048 和 SHA-256 为例生成密钥和证书的说明。
Note: 创建一个文件夹并在同一位置执行命令，并确保在 Linux 计算机上执行这些步骤。

Note: 对于 ECC，请将 `rsa:2048` 替换为 `ec:secp384r1` 或 `ec:secp256r1`。对于 SHA384，请在以下命令中将 `-sha256` 替换为 `-sha384`。

**Parent Topic:** [启用 UEFI 安全启动](https://docs.qualcomm.com/doc/80-70014-11Y/topic/enable-uefi-secure-boot.html)

## 生成 UID

Source: [https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html](https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html)

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

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

    uuidgen --random > GUID.txtCopy to clipboard

## 创建 PK 密钥

Source: [https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html](https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html)

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

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

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

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

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

## 创建 KEK 密钥

Source: [https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html](https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html)

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

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

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

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

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

## 创建 DB 密钥

Source: [https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html](https://docs.qualcomm.com/doc/80-70014-11Y/topic/generate-key-and-certificate.html)

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 -sha256Copy to clipboard
2. 将 `.crt` 文件转换为 `.cer` 文件：

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

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

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

Last Published: Aug 27, 2024

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