若要创建 PFX 或 P12 文件,请使用以下 OpenSSL 命令:
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt
openssl pkcs12 -export -out certificate.p12 -inkey privateKey.key -in certificate.crt
注意:
您的 .pfx 文件将在命令提示符中使用的证书路径中可用。
例如:
openssl pkcs12 -export -out c:\pfxexample\certificate.pfx -inkey c:\createpfx\private.key -in c:\pfxexample\certificate.crt
使用 OpenSSL 将 PEM 转换为 PKCS12 文件的步骤
要通过 OpenSSL 将 PEM 转换为 PKCS12 文件,请使用以下命令:
openssl pkcs12 -export -inkey <private_key_file.pem> -in <certificate_file.pem> -out <output_file.p12>
输入后,系统会要求您输入用于加密 PKCS12 文件的密码,其中:
<private_key_file.pem>是PEM私钥路径。
<certificate_file.pem>是PEM证书的路径
<output_file.p12> 是您希望为 PKCS12 文件保留的名称。
运行以下命令,使用 OpenSSL 从 PEM 文件创建 PFX:
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.pem
以下 OpenSSL 命令用于将 PEM 转换为 PFX 文件:
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.pem -in certificate.pem -passin pass:your_password -passout pass:your_password
用户在生成 PFX/P12 文件时经常遇到错误。以下是一些常见问题:
以下是解决此类问题的解决方案:
在导出和导入 PFX 文件时,请确认使用正确的密码。
确保使用的证书与 PFX 导出兼容。
运行以下命令,检查私钥是否与证书匹配:
openssl x509 -noout -modulus -in certificate.crt | openssl md5 openssl rsa -noout -modulus -in privateKey.key | openssl md5
如果哈希值匹配,则私钥正确。
检查导出时是否包含所有需要的中间证书。
openssl pkcs12 -info -in certificate.pfx -noout –nodes
如果缺少中间证书,请使用 -certfile 选项附加它。
上一条: 如何在 Windows Server 中导入 pfx (.p12) 证书
下一条: 没有了