ssl-guides 2026-12-02 ⏱ 1 min read

SSL 证书格式转换

SSL 证书格式转换
简短回答: 用 SSL Converter 或 OpenSSL 换格式:Nginx 和 Apache 用 PEM, PFX 给 Windows IIS 和 Azure,DER 给 Java 和设备。转换过程中私钥要保密。

你的服务器要哪种格式?

格式扩展名含私钥?典型用途
PEM(Base64 文本).pem .crt .cer .key私钥是单独的文件Nginx、Apache、cPanel、Linux
PKCS#12.pfx .p12含,有密码保护Windows IIS、Azure、Exchange、Tomcat
DER(二进制).der .cer不含Java 和嵌入式设备
PKCS#7.p7b .p7c不含,只有链Windows 导入、Tomcat

文件以 -----BEGIN CERTIFICATE-----开头就是 PEM。

SSL 证书转换:OpenSSL 命令

# PEM certificate to DER
openssl x509 -in certificate.crt -outform der -out certificate.der

# DER to PEM
openssl x509 -inform der -in certificate.der -out certificate.pem

# PEM + key + chain to PFX
openssl pkcs12 -export -out certificate.pfx \
  -inkey private.key -in certificate.crt -certfile ca_bundle.crt

# PFX back to PEM (certificate and key)
openssl pkcs12 -in certificate.pfx -nodes -out all.pem

# P7B to PEM
openssl pkcs7 -print_certs -in certificate.p7b -out certs.pem

导出 PFX 会要求设置密码。选一个强密码,存进密码管理器。 -nodes 选项会把私钥写成不加密的形式,用完就把那个文件删掉。

安全地使用浏览器里的转换器

浏览器里的 SSL Converter 不用终端就能做同样的转换。私钥等于对证书的完全控制,所以只粘贴到你信任的工具里,生产环境的私钥优先用本地 OpenSSL。公开证书和链不含机密,可以放心查看。

检查结果

  1. 用 SSL Decoder 读转换后的文件,确认主体名称和日期。
  2. 确认私钥匹配:比较证书和私钥的公钥哈希。
  3. 安装后,用 Live SSL Checker 检查链和有效期。
openssl x509 -in certificate.crt -noout -pubkey | openssl sha256
openssl pkey -in private.key -pubout | openssl sha256

两个哈希必须完全一致。

SSL 证书转换:常见错误

错误原因修法
unable to load certificate输入格式参数不对二进制文件要加 -inform der。
No certificate matches private key私钥和证书来自两次不同的申请用原始 CSR 生成的那把私钥
IIS 显示没有私钥生成 PFX 时没带私钥重新导出时加 -inkey
链警告缺少中间证书加 -certfile ca_bundle.crt

相关阅读: 把 PFX 转成 PEM, 把 CRT 转成 PEM 和 把 PEM 转成 Java keystore.

常见问题

没有密码能把 PFX 转成 PEM 吗?

不能。打开内容必须用密码。

转换会改变证书吗?

不会。内容和有效期不变,只有容器变了。

CRT 和 CER 有什么区别?

都只是文件扩展名。要看内容是 PEM 还是 DER。

上传证书安全吗?

公开证书不是机密。绝不要把私钥上传到你不信任的服务。

🔄 Convert PEM Certificate to Windows .PFX Online
Convert PEM → PFX →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

免费 SSL 证书签发、在线 SSL 检测与 CSR 生成器

无需复杂服务器配置,60 秒快速获取 Let's Encrypt 与 Buypass 信任的 HTTPS 证书。

Related Articles

🤖 TryFreeSSL AI Assistant