使用 OpenSSL 将 PKCS#12 证书转换为 PEM [英] Converting PKCS#12 certificate into PEM using OpenSSL

查看:28
本文介绍了使用 OpenSSL 将 PKCS#12 证书转换为 PEM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 上安装了 OpenSSL x64,我从 在谷歌代码上打开ssl-for-windows.我正在尝试运行:

I have OpenSSL x64 on Windows 7 which I downloaded from openssl-for-windows on Google Code. I'm attempting to run:

openssl pkcs12 -export -in "path.p12" -out "newfile.pem" 

但是我得到一个错误.

unable to load private key

如何使用 OpenSSL 从 PKCS#12 存储中提取 PEM 中的证书?

How do I extract the certificate in PEM from PKCS#12 store using OpenSSL?

推荐答案

尝试:

openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys
openssl pkcs12 -in path.p12 -out newfile.key.pem -nocerts -nodes

之后你有:

  • newfile.crt.pem 中的证书
  • newfile.key.pem 中的私钥

要将证书和密钥放在同一个文件中而无需密码,请使用以下内容,因为密码为空会导致密钥无法导出:

To put the certificate and key in the same file without a password, use the following, as an empty password will cause the key to not be exported:

openssl pkcs12 -in path.p12 -out newfile.pem -nodes

或者,如果你想为私钥提供密码,省略-nodes并输入密码:

Or, if you want to provide a password for the private key, omit -nodes and input a password:

openssl pkcs12 -in path.p12 -out newfile.pem

如果需要直接从命令行输入 PKCS#12 密码(例如脚本),只需添加 -passin pass:${PASSWORD}:

If you need to input the PKCS#12 password directly from the command line (e.g. a script), just add -passin pass:${PASSWORD}:

openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys -passin 'pass:P@s5w0rD'

这篇关于使用 OpenSSL 将 PKCS#12 证书转换为 PEM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆