导入.p12文件中包含的所有证书 [英] Importing all certificates contained in a .p12 file

查看:75
本文介绍了导入.p12文件中包含的所有证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .p12 文件,供我的ASP.NET应用程序通过HTTPS连接到Web服务.

I have a .p12 file for my ASP.NET application to connect to a web service via HTTPS.

我正在尝试将 .p12 文件导入本地计算机/我的商店. .p12 文件包含多个证书.一个包含私钥,另一个是完成链的CA证书.

I am trying to import the .p12 file into the Local Machine/My store. The .p12 file contains more than one certificate. One contains the private key and the other is the CA certificate to complete the chain.

当前,我正在使用`System.Security.Cryptography.X509Certificates.X509Certificate2对象的Import方法将此文件导入到存储中.今天,我注意到没有导入CA证书,仅使用此方法导入包含私钥的主证书.在进一步审查MSDN之后,我发现了有关导入方法的以下规则:

Currently I am using the `System.Security.Cryptography.X509Certificates.X509Certificate2 object's Import method to import this file into the store. Today I noticed that the CA certificate is not getting imported, only the main certificate containing the private key is getting imported using this method. After further review of MSDN I have found the following rule regarding the Import method:

请注意,PFX/PKCS12证书可以包含多个证书.在这种情况下,将使用与私钥关联的第一个证书,或者,如果找不到私钥,则使用第一个证书.

Note that a PFX/PKCS12 certificate can contain more than one certificate. In that case, the first certificate associated with a private key is used or, if no private key is found, the first certificate is used.

有人可以建议我通过编程方式导入 .p12 文件的另一种方法,该方法实际上将导入该文件中的所有证书吗?我正在使用 PowerShell 来执行此功能.

Can anyone suggest to me another method for importing the .p12 file programmatically that will actually import all certificates in the file? I am using PowerShell to perform this function.

推荐答案

使用X509Certificate2Collection.Import方法代替使用X509Certificate2.Import方法.它将为您提供.p12文件中的所有证书.

Instead of using the X509Certificate2.Import method, use the X509Certificate2Collection.Import method. It will give you all certificates from the .p12 file.

然后您可以将每个证书添加到其相应的存储中.

You can then add each certificate to its appropriate store.

这篇关于导入.p12文件中包含的所有证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆