将PFX转换为包括中间证书的密钥的PEM格式

5
我有一个PFX文件,想要将其转换为CRT和Key或PEM和Key以在NGINX端点上安装。当我将pfx导入我的Windows机器的证书存储时,它会创建证书、中间链和根CA。
如果我将该PFX文件运行以下openssl命令并绑定到端点,则无法获取链中的所有证书:
openssl pkcs12 -in ./GoDaddy.pfx -clcerts -nokeys -out pcc.crt -nodes -nokeys

openssl pkcs12 -in ./GoDaddy.pfx -nocerts -nodes -out pcc.rsa -nodes -nokeys

有没有一个开关或命令可以运行,将PFX转换为带有整个证书链到根CA的crt / rsa或pem / key?

2个回答

16

既然您想要所有东西,您只需要减少所要求的限制数量。

因此:

openssl pkcs12 -in ./GoDaddy.pfx -out ./GoDaddy.pem

如果您阅读文档,您将看到您所要求的内容:

-nocerts

No certificates at all will be output.

-clcerts

Only output client certificates (not CA certificates).

-nokeys

No private keys will be output.

-nodes

Don't encrypt the private keys at all.

谢谢回复!我尝试了一下,但是没有成功。我觉得可能是因为当我尝试创建密钥时:sudo openssl pkcs12 -in ./GoDaddy.pfx -nocerts -out pcc.rsa 没有起作用。这是因为它只为其中一个证书创建了密钥,而不是整个证书链吗? - Eitan
是的,-nocerts 只会提取密钥。 - Shane Powell

3

您可以使用此方法从 .pfx 文件中提取 ca-bundle、.crt 和 .key。

# Extracting ca-certs..."
  openssl pkcs12 -in ${filename}.pfx -nodes -nokeys -cacerts -out ${filename}-ca.crt

# Extracting key file..."
  openssl pkcs12 -in ${filename}.pfx -nocerts -out ${filename}.key

# Extracting crt..."
  openssl pkcs12 -in ${filename}.pfx -clcerts -nokeys -out ${filename}.crt

# combine ca-certs and cert files
  cat  ${filename}.crt ${filename}-ca.crt > ${filename}-full.crt

# Removing passphrase from keyfile"
  openssl rsa -in ${filename}.key -out ${filename}.key

Link: https://gist.github.com/mediaupstream/a2694859b1afa59f26be5e8f6fd4806a


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接