如何将pem转换为pfx文件



这让我很困惑:

Convert pfx to PEM:
openssl pkcs12 -in certificatename.pfx -out certificatename.pem

这样做会转储一个单个纯文本文件。

现在我如何将这个纯文本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等)的类似问题显然被社区接受(向上投票)-但我没有看到直接解决这一点。

openssl pkcs12 -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

,你甚至可以组合碎片'在飞行',只要你把私钥放在第一位:

 cat privkey.pem mycert.pem chain.pem | openssl pkcs12 -export -out p12

可以使用下面的命令转换PEM (. pem, .crt, .cer)到PFX:

openssl pkcs12 -export -out **<your_new_file_name>**.pfx -inkey **<private_key_of_your_existing_certificate>**.key -in **<your_existing_certificate_file>**.crt

这对于上面提到的所有文件来说都是非常通用的。

最新更新