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

把 PFX 转换为 PEM

把 PFX 转换为 PEM

.pfx 文件(也叫 .p12)是 PKCS#12 容器,里面打包了证书、对应的私钥,通常还有中间证书链,并用密码保护。Apache、Nginx 和大多数 Linux 工具要的是 PEM 文件。OpenSSL 可以替你拆分这个容器。

文件格式一览

格式扩展名内容常见用途
PKCS#12.pfx、.p12证书、私钥、证书链,有密码保护Windows、IIS、Java
PEM.pem、.crt、.keyBase64 文本,一项或多项Apache、Nginx、Linux
DER.der、.cer二进制证书Java、部分设备

把所有内容导出到一个文件

openssl pkcs12 -in example.pfx -out all.pem -nodes

提示时输入导入密码。-nodes 选项会让私钥不加密,所以请保护好输出文件。用文本编辑器打开 all.pem,如果需要单独的文件就把各段拆开。

PFX 转 PEM:分别导出每一部分

# Certificate only
openssl pkcs12 -in example.pfx -clcerts -nokeys -out certificate.pem

# Private key only (unencrypted)
openssl pkcs12 -in example.pfx -nocerts -nodes -out private.key

# CA chain only
openssl pkcs12 -in example.pfx -cacerts -nokeys -chain -out chain.pem

证书输出可能以 "Bag Attributes" 开头的几行。如果服务器报错,把 BEGIN 和 END 行以外的内容全部删掉。

检查结果

  1. 用Key Matcher确认私钥与证书匹配。
  2. 用SSL Decoder查看证书详情。
  3. 安装文件,重载服务器,然后运行SSL Checker。

如果你不想用终端,SSL Converter 能做同样的转换。不要把私钥上传到你不信任的工具。在本地运行 OpenSSL 可以让私钥留在你的机器上。

PFX 转 PEM:常见错误

  • Mac verify error: invalid password? 导入密码不对。检查有没有输错,或者问创建文件的人。
  • Unsupported algorithm,或在 OpenSSL 3 中报 "unsupported":文件使用了旧的加密方式。在命令里加上 -legacy,这需要 legacy provider 可用。
  • 私钥文件为空:PFX 里可能只有证书。你需要原始私钥。

反过来转换

要从 PEM 文件生成 PFX,使用 openssl pkcs12 -export。我们在 IIS 上安装 SSL 的指南给出了完整命令。

相关阅读:把 CRT 转换为 PEM、把 PEM 转换为 Java keystore、在 Windows 主机上安装 PFX 和 certificate verify failed 错误。

常见问题

.p12 文件和 .pfx 一样吗?

一样。两者都是 PKCS#12。扩展名因平台而异。

要保留 PFX 密码吗?

存到密码管理器里。没有它,文件打不开。

能直接拿到 PEM 格式的免费证书吗?

TryFreeSSL 提供 PEM 文件,所以只有面向 Windows 时才需要转换 PFX。

让私钥不加密安全吗?

在服务器上,私钥文件通常不加密,但必须只有服务账户能读。设置类似 chmod 600 的权限。

🔄 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