首页 > 解决方案 > 当我在生成 PFX 文件时不包含 .cert 文件的所有层次结构时会发生什么

问题描述

Ì 我正在尝试 a) 从可用的证书文件和私有文件中导出 PFX 文件,当我使用如下所示的所有可用证书层次结构导出时 - 我收到以下错误

pkcs12 -export -out C:\Users\YSW\SCI\prp\preproduction-abc.com.pfx -inkey C:\Users\YSW\PCI\prp\pk.preproduction-abc.com.txt -in C:\Users\YSW\SCI\prp\pk.preproduction-abc.com.txt -in C:\Users\YSW\PCI\prp\TrustedSecureCertificateAuthority5.crt -in C:\Users\YSW\PCI\prp\USERTrustRSAAddTrustCA.crt -in C:\Users\YSW\PCI\prp\AddTrustExternalCARoot.crt

错误 ""没有证书匹配私钥,pkcs12 中的错误""

b)当我删除层次结构中的证书并只保留主证书时,如下所示,它对我来说很好,没有任何错误

pkcs12 -export -out C:\Users\YSW\SCI\prp\preproduction-abc.com.pfx -inkey C:\Users\YSW\PCI\prp\pk.preproduction-abc.com.txt -in C:\Users\YSW\SCI\prp\pk.preproduction-abc.com.txt

在我将此 PFX 文件上传到服务器之前,我想确保在生成 PFX 文件时排除层次结构中的其他证书是否可以

请注意,当我在证书中看到它时,我已经在层次结构中给出了证书,首先是层次结构中最低的,最后是层次结构中最高的

""-在 C:\Users\YSW\SCI\prp\pk.preproduction-abc.com.txt -在 C:\Users\YSW\PCI\prp\TrustedSecureCertificateAuthority5.crt -在 C:\Users\YSW\PCI \prp\USERTrustRSAAddTrustCA.crt -在 C:\Users\YSW\PCI\prp\AddTrustExternalCARoot.crt""

我想知道如果我继续使用从主证书导出的 PFX 会发生什么,或者让我知道如何克服 No certificate matches the Private Key 错误的问题

标签: opensslpfx

解决方案


openssl pkcs12 命令只允许“-in”参数使用 1 个参数。因此多次指定它,它只会采用唯一的最后一个参数,这就是您收到错误消息的原因。

通常如果只想添加一个中间证书,您还可以指定“-certfile”参数以在 PFX 文件中再添加一个证书。由于您要添加多个额外的证书,因此最好的方法是将所有证书合并到一个文件中。

所有这些文件都应该是文本文件,所以我会将所有这些文件合并到一个文件中,并将它们作为一个“-in”参数传递。

例如(对于窗户)

copy pk.preproduction-abc.com.txt+TrustedSecureCertificateAuthority5.crt+USERTrustRSAAddTrustCA.crt+AddTrustExternalCARoot.crt allcertificates.pem

(对于 Linux)

cat pk.preproduction-abc.com.txt TrustedSecureCertificateAuthority5.crt USERTrustRSAAddTrustCA.crt AddTrustExternalCARoot.crt > allcertificates.pem

然后将 allcertificates.pem 转换为 pfx:

openssl pkcs12 -export -in allcertificates.pem -out preproduction-abc.com.pfx

推荐阅读