把 CRT 转换为 PEM
openssl x509 -inform DER -in certificate.crt -out certificate.pem -outform PEM 转换。先检查格式
.crt 和 .cer 这类扩展名只说明"证书",不说明编码。
head -n 1 certificate.crt
| 你看到什么 | 格式 | 该怎么做 |
|---|---|---|
-----BEGIN CERTIFICATE----- | PEM(文本) | 需要时改名为 .pem |
| 不可读的二进制字符 | DER(二进制) | 用 OpenSSL 转换 |
CRT 转 PEM:把 DER 转成 PEM
openssl x509 -inform DER -in certificate.crt -out certificate.pem -outform PEM
你也可以反过来:
openssl x509 -in certificate.pem -outform DER -out certificate.der
免费的SSL Converter不用命令行就能做同样的事。
检查结果
openssl x509 -in certificate.pem -noout -subject -issuer -dates
这会显示证书是发给谁的、由谁签发、什么时候到期。你也可以把它粘贴到SSL Decoder里。
CRT 转 PEM:拼出证书链文件
Nginx 这类服务器要求先放叶子证书,再放中间证书,全部为 PEM:
cat certificate.pem intermediate.pem > fullchain.pem
安装后用SSL Checker检查结果。如果你的 CA 给你的是 .p7b 文件,这样导出证书:
openssl pkcs7 -print_certs -in bundle.p7b -out bundle.pem
常见错误
- 去转换一个本来就是 PEM 的文件,用
-inform DER时会报 "unable to load certificate"。 - 把证书和私钥搞混。私钥以
-----BEGIN PRIVATE KEY-----或BEGIN RSA PRIVATE KEY开头。 - 粘贴的文件里有多余空格或 Windows 换行符。
- 忘了中间证书,导致证书链错误。
需要 PFX 而不是 PEM?
IIS 和 Windows 请看我们的PEM 转 PFX 指南。如果你在创建新证书,可以从TryFreeSSL.com开始,或用CSR Generator生成请求。
相关阅读:把 PFX 转换为 PEM、生成私钥和 CSR 和 证书链。
常见问题
CRT 和 PEM 一样吗?
定义上不一样。CRT 是扩展名。内容通常是 PEM,但也可能是 DER。
可以直接改文件名吗?
只有它本来就是 PEM 文本时才行。给 DER 文件改名不会改变它的编码。
转换会改变证书吗?
不会。只改变编码,签名和内容保持不变。
Nginx 要哪种格式?
PEM,先叶子证书,再中间证书。
✅ 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
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.