# 密钥用途

**密钥用途**（Key usage）是 X.509 v3 证书的一种扩展，由对象标识符 id-ce-keyUsage（{ id-ce 15 }）标识，用于规定证书中所含公钥的用途，例如加密、签名验证或证书签名。该扩展定义于 RFC 5280《互联网 X.509 公钥基础设施证书与 CRL 概要》第 4.2.1.3 节，编码为 BIT STRING，其中每个命名位对应一种允许的密码学操作。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>

| 关键事实 | 详情 |
|---|---|
| 用途 | 规定证书中所含密钥的用途（如加密、签名、证书签名），从而限制一把本可承担多种操作的密钥。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> |
| 语法 | KeyUsage ::= BIT STRING，含九个命名位：digitalSignature (0)、nonRepudiation (1)、keyEncipherment (2)、dataEncipherment (3)、keyAgreement (4)、keyCertSign (5)、cRLSign (6)、encipherOnly (7)、decipherOnly (8)。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> |
| 对象标识符 | id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 }。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> |
| 关键性 | 符合规范的 CA 应将此扩展标记为关键；使用证书的系统必须拒绝含有其无法处理的关键扩展的证书。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> |
| CA 密钥的强制性 | 当证书所含公钥用于验证其他公钥证书或 CRL 上的数字签名时，CA 必须在证书中包含此扩展。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> |
| 算法约束 | 对于 X25519 或 X448 密钥，keyUsage 必须声明 keyAgreement，且不得声明 digitalSignature、nonRepudiation、keyEncipherment、dataEncipherment、keyCertSign 或 cRLSign。<sup>[2](https://datatracker.ietf.org/doc/rfc9295/)</sup> |
| 与 EKU 的交互 | 若 keyUsage 与扩展密钥用途同时存在，二者必须独立处理，证书只能用于同时符合二者的用途。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> |

## 九个位

KeyUsage BIT STRING 中的每一位声明主体公钥的一种允许用途：<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>

- **digitalSignature (0)**：当密钥用于验证证书（第 5 位）和 CRL（第 6 位）以外的数字签名时声明，例如用于实体认证、数据源认证或完整性服务的签名。
- **nonRepudiation (1)**：当密钥用于验证提供不可否认服务的签名时声明，该服务防止签名实体虚假否认某一行为；较新版本的 X.509 已将这一位更名为 contentCommitment。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>
- **keyEncipherment (2)**：当公钥用于加密私有密钥或秘密密钥，即用于密钥传输时声明。用于加密对称内容解密密钥的 RSA 公钥会设置此位。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>
- **dataEncipherment (3)**：当公钥直接加密原始用户数据、不经中间对称密码时声明。根据 RFC 5280，此位很少设置，因为几乎所有应用都改用密钥传输或密钥协商来建立对称密钥。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>
- **keyAgreement (4)**：当公钥用于密钥协商时声明，例如 Diffie-Hellman 密钥用于密钥管理时。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>
- **keyCertSign (5)**：当密钥用于验证公钥证书上的签名时声明。若声明此位，则基本约束扩展中的 cA 位也必须声明。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>
- **cRLSign (6)**：当密钥用于验证证书吊销列表上的签名时声明，包括 CRL、增量 CRL 和 ARL。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>
- **encipherOnly (7)** 与 **decipherOnly (8)**：仅在配合 keyAgreement 时才有意义；缺少 keyAgreement 时其含义未定义。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>

该扩展限制一把原本可用于多种操作的密钥。例如，当 RSA 密钥只应验证证书和 CRL 以外对象上的签名时，声明 digitalSignature 和/或 nonRepudiation 位；当 RSA 密钥只应用于密钥管理时，声明 keyEncipherment 位。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>

## 关键性与强制执行

存在时，符合规范的 CA 应将 keyUsage 标记为关键。关键标志之所以重要，是因为使用证书的系统必须拒绝含有其不识别或无法处理的关键扩展的证书，而非关键扩展在不被识别时可以忽略。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup>

[证书颁发机构](https://www.edgepedia.org/zh/certificate-authority)基线要求强化了 CA 密钥上的这一扩展。根据 [CA/浏览器论坛基线要求](https://www.edgepedia.org/zh/ca-browser-forum-baseline-requirements)，根 CA 证书和从属 CA 证书中的 keyUsage 扩展必须存在且必须标记为关键，并设置 keyCertSign 和 cRLSign 位；若 CA 私钥签署 OCSP 响应，则还必须设置 digitalSignature 位。<sup>[3](https://cabforum.org/uploads/CA-Browser-Forum-BR-1.6.3.pdf)</sup>

## 算法特定规则

算法概要约束哪些位组合有效。对于 Diffie-Hellman 公钥，RFC 2459 允许 keyAgreement、encipherOnly 和 decipherOnly，且 encipherOnly 与 decipherOnly 至多声明其一。<sup>[4](https://www.rfc-editor.org/info/rfc2459/)</sup> RFC 3279 对椭圆曲线 Diffie-Hellman 密钥沿用同一规则：若存在 keyUsage 扩展，必须声明 keyAgreement，可以声明 encipherOnly 或 decipherOnly 之一，且不得同时声明二者。<sup>[5](https://www.rfc-editor.org/rfc/rfc3279.html)</sup>

RFC 9295 澄清了 Ed25519、Ed448、X25519 和 X448 算法标识符，以“必须”级别的措辞陈述了这些规则。对于 X25519 或 X448 密钥，必须存在 keyAgreement，可以存在 encipherOnly 或 decipherOnly 之一，与签名相关的位不得存在。对于 Ed25519 或 Ed448 终端实体证书，keyUsage 必须至少包含 nonRepudiation、digitalSignature 或 cRLSign 之一，与加密和协商相关的位不得存在。对于 Ed25519 或 Ed448 密钥的 CRL 签发者证书，必须存在 cRLSign；若 CRL 签发者同时是认证机构，则还必须存在 keyCertSign。<sup>[2](https://datatracker.ietf.org/doc/rfc9295/)</sup>

## 与扩展密钥用途的关系

扩展密钥用途（EKU）扩展定义于 RFC 5280 第 4.2.1.12 节，通过 KeyPurposeId 对象标识符在更高层面指示用途，例如 id-kp-serverAuth（TLS WWW 服务器认证）、id-kp-clientAuth、id-kp-codeSigning 和 id-kp-emailProtection。若存在 EKU 扩展，证书只能用于所指示的用途之一；若指示了多种用途，只要预期用途在其中，应用无需识别全部用途。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> 当两种扩展同时出现时，必须独立处理，证书只能用于同时符合二者的用途；若不存在同时符合二者的用途，则证书不得用于任何用途。<sup>[1](https://www.rfc-editor.org/info/rfc5280/)</sup> RFC 9809 为配置、更新和安全关键通信定义了 KeyPurposeId，要求证书请求者确保 keyUsage 扩展在签名验证时设为 digitalSignature、在公钥加密时设为 keyEncipherment、在密钥协商时设为 keyAgreement，使 EKU 用途与底层位相匹配。<sup>[6](https://www.rfc-editor.org/rfc/rfc9809.html)</sup>

## 在 TLS 与验证中的使用

[TLS 1.3](https://www.edgepedia.org/zh/tls-1-3) 将证书选择与这一扩展绑定：服务器的终端实体证书必须允许该密钥用于签名，即若存在 keyUsage 扩展，必须设置 digitalSignature 位，且所用签名方案须在客户端的 signature_algorithms 扩展中列出。<sup>[7](https://www.rfc-editor.org/info/rfc8446/)</sup> TLS 1.3 还定义了匹配规则：当请求中声明的所有密钥用途位也在证书扩展中声明时，证书中的 keyUsage 扩展与请求匹配。<sup>[7](https://www.rfc-editor.org/info/rfc8446/)</sup>

该扩展在吊销检查中同样重要。RFC 5280 要求 CRL 签发者证书包含 keyUsage 且声明 cRLSign 位，但其第 6.3 节的 CRL 验证算法仅在扩展存在时才检查 cRLSign 位，并不要求扩展本身存在。RFC 10007 更新了该算法：对于版本 3 的 CRL 签发者证书，验证器现在必须核实 keyUsage 扩展存在且 cRLSign 已设置。这一改动堵住了一种情形：持有无 keyUsage 证书的实体可以签署依赖方会接受的 CRL，因为扩展缺失时位检查被跳过。<sup>[8](https://www.rfc-editor.org/rfc/rfc10007.html)</sup>

## 工具支持

OpenSSL 在其 X.509 v3 配置中将该扩展暴露为多值扩展，由允许的密钥用途名称列表组成，支持 digitalSignature、nonRepudiation（较新版本中另有别名 contentCommitment）、keyEncipherment、dataEncipherment、keyAgreement、keyCertSign、cRLSign、encipherOnly 和 decipherOnly 等名称；例如，CA 证书可写作 keyUsage = critical, keyCertSign。<sup>[9](https://docs.openssl.org/4.0/man5/x509v3_config/)</sup> OpenSSL 的 x509 文档指出，若存在 keyUsage 扩展，CA 证书必须设置 keyCertSign 位。<sup>[10](https://docs.openssl.org/1.0.2/man1/x509/)</sup>

## References

1. [RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile, RFC Editor](https://www.rfc-editor.org/info/rfc5280/)
2. [RFC 9295: Clarifications for Ed25519, Ed448, X25519, and X448 Algorithm Identifiers, IETF](https://datatracker.ietf.org/doc/rfc9295/)
3. [CA/Browser Forum Baseline Requirements v1.6.3](https://cabforum.org/uploads/CA-Browser-Forum-BR-1.6.3.pdf)
4. [RFC 2459: Internet X.509 Public Key Infrastructure Certificate and CRL Profile, RFC Editor](https://www.rfc-editor.org/info/rfc2459/)
5. [RFC 3279: Algorithms and Identifiers for the Internet X.509 PKI, RFC Editor](https://www.rfc-editor.org/rfc/rfc3279.html)
6. [RFC 9809: X.509 Certificate Extended Key Usage (EKU) for Configuration, Updates, and Safety-Critical Communication, RFC Editor](https://www.rfc-editor.org/rfc/rfc9809.html)
7. [RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3, RFC Editor](https://www.rfc-editor.org/info/rfc8446/)
8. [RFC 10007: Clarification to Processing Key Usage Values During Certificate Revocation List (CRL) Validation, RFC Editor](https://www.rfc-editor.org/rfc/rfc10007.html)
9. [x509v3_config, OpenSSL Documentation](https://docs.openssl.org/4.0/man5/x509v3_config/)
10. [x509, OpenSSL Documentation](https://docs.openssl.org/1.0.2/man1/x509/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Security governance and internet policy › Cryptographic protocols › Key management

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/key-usage

English original: https://www.edgepedia.org/key-usage
