SSL 转换常见问题
关于 SSL 证书格式转换的常见问题
证书格式比较
| 格式 | 扩展名 | 编码 | 用途 |
|---|---|---|---|
| PEM | .pem, .crt, .key | Base64 (ASCII) | 最常见格式,用于 Apache、Nginx |
| DER | .der, .cer | 二进制 (DER) | 二进制格式,用于 Java 及部分 Windows 应用 |
| P7B/PKCS#7 | .p7b, .p7c | Base64 (ASCII) | 证书链格式,用于 Windows |
| PFX/PKCS#12 | .pfx, .p12 | 二进制 (DER) | 包含私钥的存档格式,用于 Windows/IIS |
常见转换
PEM → DER
将 PEM 转换为 DER 二进制格式
openssl x509 -in cert.pem -outform DER -out cert.derDER → PEM
将 DER 二进制转换为 PEM 文本格式
openssl x509 -in cert.der -inform DER -outform PEM -out cert.pemPEM → P7B
将 PEM 证书转换为 PKCS#7 格式
openssl crl2pkcs7 -nocrl -certfile cert.pem -out cert.p7bP7B → PEM
将 PKCS#7 转换为 PEM 证书格式
openssl pkcs7 -in cert.p7b -print_certs -out cert.pemPEM → PFX
将 PEM 证书和密钥转换为 PFX 存档
openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.pem -certfile chain.pemPFX → PEM
从 PFX 存档中提取 PEM 证书和密钥
openssl pkcs12 -in cert.pfx -out cert.pem -nodes提示
- 转换前务必备份您的证书
- 转换过程中请保管好您的私钥
- 验证转换后的证书是否正常工作
- 部分转换需要私钥密码