gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:57:07 24 4
gpt4 key购买 nike

我正在尝试将扩展名为 .p7b 的证书 (smime) 导入到 Windows 应用商店。

这是当前代码

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

它给了我一个错误“找不到原始签名者”。

Remark: This code is working with .cer extensions (DER & Base 64).

有人请帮助确定可能的根子句吗?

谢谢。

附言。 VS2010、Windows Server 2008 R2

Edit1:test_public_cert.p7b 是通过 mmc 控制台从另一台服务器上的公钥导出的。

最佳答案

我过去在使用 .p7b 扩展名时遇到过这个问题。我发现有两种方法可以解决这个问题。最后我最终使用了数字 1。数字 2 是您通过导出到 .cer 已经找到的东西。您也可以尝试使用选项 3,但我不确定它是否完全有效。

1.使用 SignedCms而不是 X509Certificate 类。

查看更多详情Enveloped PKCS #7 Signatures

2。加载 .p7b 仅包含证书文件,可能不包含私钥。在生成私钥的服务器上安装私钥,然后将其导出为 .pfx 文件并将其移动到您要使用的服务器。

3。由于 .p7b 文件包含整个证书链而不仅仅是一个证书,您可以尝试按照以下方法将其添加到 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);

关于C#,无法将 .p7b 证书导入 Windows 应用商店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22753703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com