Windows 如何将pem转换为pfx文件?

Windows 如何将pem转换为pfx文件?,windows,openssl,certificate,ssl-certificate,pfx,Windows,Openssl,Certificate,Ssl Certificate,Pfx,: 执行此操作将转储一个纯文本文件 现在我如何将这个纯文本pem转换回pfx 我看到的唯一转换为pfx的命令需要cer和私钥在单独的文件中: Convert CER and Private Key to PFX: openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile cacert.cer 虽然我同意这不是真正的编程,也可以说是离题的

:

执行此操作将转储一个纯文本文件

现在我如何将这个纯文本pem转换回pfx

我看到的唯一转换为pfx的命令需要cer和私钥在单独的文件中:

Convert CER and Private Key to PFX:    
openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile  cacert.cer

虽然我同意这不是真正的编程,也可以说是离题的,但社区显然接受了许多关于(加密)密钥和证书的命令行工具(openssl、keytool、certutil等)的类似Qs(向上投票)——但我所看到的没有一个直接解决这一点

opensslpkcs12-export
上的不同选项允许您在不同的文件中提供片段,但这不是必需的。如果您确实在一个PEM文件中拥有私钥和证书链,默认情况下,
pkcs12[not-export]
您可以从该文件读取所有内容

 openssl pkcs12 -export -in file -out p12
 # or ONLY IF the privatekey is first in the file
 openssl pkcs12 -export <file -out p12

您可以使用以下命令将PEM(.PEM、.crt、.cer)转换为PFX:

opensslpkcs12-export-out****.pfx-inkey****.key-in****.crt

这对于上述所有文件都是非常通用的。

Stack Overflow是一个关于编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参见帮助中心中的。ASN1./DER和PEM是编码或表示格式。这是用
-inform
-outform
-certform
等指定的。可能重复:和@jww+,尽管OpenSSL通常使用-inform、-outform等,但
pkcs12
是一个例外。P12文件本身始终是DER never PEM,从P12导入或导出到P12的密钥和证书仅支持作为PEM。但他询问如何将包含证书和私钥的单个PEM文件(而不是单独的证书和私钥文件)转换为PFX。
 openssl pkcs12 -export -in file -out p12
 # or ONLY IF the privatekey is first in the file
 openssl pkcs12 -export <file -out p12
 cat privkey.pem mycert.pem chain.pem | openssl pkcs12 -export -out p12
openssl pkcs12 -export -out **<your_new_file_name>**.pfx -inkey **<private_key_of_your_existing_certificate>**.key -in **<your_existing_certificate_file>**.crt