首页 文章

将.pem和.pub转换为.pfx文件

提问于
浏览
0

我有.pem文件和.pub文件,我使用以下命令来创建它们

openssl genrsa -out temp.pem 1024
openssl rsa -in temp.pem -pubout -out temp.pub

现在我想把它们变成一个.pfx文件,它是二进制文件,包含私钥和公钥 . 可能吗?怎么样? (我测试过som openssl命令,但文件是空的) .

我用过这个命令

openssl pkcs12 -export -in temp.pem -inkey temp.pub -out temp.pfx -name "Temp Certificate"

它会生成此错误:

无法加载私钥17880:错误:0906D06C:PEM例程:PEM_read_bio:无起始行: . \ crypto \ pem \ pem_li b.c:703:期望:任何私钥

1 回答

  • 4

    您收到错误,因为对于 -inkey 参数,您必须指定私钥;不是公钥 .

    OpenSSL的pkcs12命令不提供将公钥和私钥合并到单个文件中的方法 . 它专门用于将证书和私钥合并到一个文件中 . 在上面的例子中,你拥有的是公钥,而不是证书 .

    从手册页:

    -in filename The filename to read certificates and private keys from, standard input by default. They must all be in PEM format. The order doesn't matter but one private key and its corresponding certificate should be present. If additional certificates are present they will also be included in the PKCS#12 file.

    请注意,它特别提到存在一个私钥及其对应的证书 should . 我通常用于生成PKCS#12文件的命令是:

    openssl pkcs12 -export -in cert.pem -inkey private.key -out file.pfx -name "My Certificate"

相关问题