简体   繁体   English

C#,无法将.p7b证书导入Windows商店

[英]C#, Unable to import .p7b certificate to windows store

I'm trying to import certificate (smime) with extension .p7b to windows store. 我正在尝试将扩展名为.p7b的证书(smime)导入到Windows应用商店。

This is the current code 这是当前的代码

X509Certificate2 cert = new X509Certificate2(@"C:\test_public_cert.p7b");
X509Store store = new X509Store(StoreName.AddressBook, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(cert);

It gave me an error that "Cannot find the original signer". 它给了我一个“无法找到原始签名者”的错误。

Remark: This code is working with .cer extensions (DER & Base 64). 备注:此代码正在使用.cer扩展(DER和Base 64)。

Anyone please help to identify the possible root clause? 有人请帮助确定可能的根条款吗?

Thanks. 谢谢。

PS. PS。 VS2010, Windows Server 2008 R2 VS2010,Windows Server 2008 R2

Edit1: test_public_cert.p7b was exported from public key on another server via mmc console. Edit1:test_public_cert.p7b是通过mmc控制台从另一台服务器上的公钥导出的。

I encountered this problem in the past with the .p7b extension. 我在过去使用.p7b扩展名遇到了这个问题。 There are two ways I found you can solve this. 我发现有两种方法可以解决这个问题。 In the end I ended up using number 1. Number 2 is something you already found out by exporting to a .cer. 最后,我最终使用数字1.数字2是您通过导出到.cer已经找到的东西。 You can also try to use option 3 but I am not sure if that will fully work. 您也可以尝试使用选项3,但我不确定这是否完全有用。

1. Use SignedCms instead of the X509Certificate class. 1.使用SignedCms而不是X509Certificate类。

See for more details Enveloped PKCS #7 Signatures 有关详细信息,请参阅Enveloped PKCS#7签名

2. Loading a .p7b only includes the certificate file, which probably doesn't include the private key. 2.加载.p7b只包含证书文件,该文件可能不包含私钥。 Install the private key on the server where it was generated and then export it to as a .pfx file and move it to the server you want to use. 在生成它的服务器上安装私钥,然后将其导出为.pfx文件并将其移动到要使用的服务器。

3. Since a .p7b file contains the whole certificate chain and not just one certificate you can try the follow method to add this to the windows store. 3.由于.p7b文件包含整个证书链而不仅仅是一个证书,您可以尝试使用follow方法将其添加到Windows应用商店。

X509Certificate2Collection certCollection = new X509Certificate2Collection();
certCollection.Import(@"C:\test_public_cert.p7b");
X509Store store = new X509Store(StoreName.AddressBook, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.AddRange(certCollection);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c# 如何从证书和密钥或 pfx 或 p7b 创建 X509 证书 - c# How to create X509 Certificate from certificate and key or pfx or p7b C#新的X509Certificate2(path)PKCS#7 / P7B-> System.Security.Cryptography.CryptographicException:'找不到对象或属性' - C# new X509Certificate2(path) PKCS#7/P7B -> System.Security.Cryptography.CryptographicException: 'Cannot find object or property' 证书数据格式 .p7b 的格式错误的内容 - Malformed content in certificate data format .p7b 如何使用 p7b 证书加密 zip 文件并使用 p12 对其进行签名 - how to encrypt zip file with p7b certificate and sign it with p12 解析没有私钥的PKCS#7 SSL证书链(.p7b)? - Parse PKCS #7 SSL Certificate Chain (.p7b) without private key? 无法导入具有私钥的证书pfx从Windows Server 2012上的.net c#3.5存储 - Cannot import certificate pfx with private key to store from .net c# 3.5 on windows server 2012 如何使用p7b和p12证书 - how to use p7b and p12 certificates 无法将证书导入到Mono商店 - Unable to import certificate to Mono store GRPC C# SSL 客户端与 Windows 证书存储 - GRPC C# SSL Client with Windows Certificate Store 在C#中将证书安装到Windows本地用户证书存储中 - Install certificates in to the Windows Local user certificate store in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM