我有一些C# 4.0代码,它试图将CA (.der编码的)证书安装到当前(我的)用户的“受信任的根证书颁发机构”存储中。我的小控制台应用程序在其他商店上静默运行,但该商店的GUI弹出窗口显示“您将要安装来自证书颁发机构的证书……Windows无法验证证书是否确实来自……您要安装此证书吗?”
这个消息框是一个问题,因为它的想法是使用MSI自动部署应用程序,并在正确的位置静默获得正确的证书。拥有一个模式箱将会扼杀自动化部署。
如何在没有部署中断消息框的情况下完成此安装?
发布于 2010-11-21 20:06:36
这听起来可能不符合逻辑,但是为了不发出警告,您不应该将证书添加到当前用户的根证书库,而应该将其添加到本地计算机的根目录。您可以轻松地验证这一点
certmgr.exe -add -c t.cer -s -r currentUser root
产生安全警告,但是
certmgr.exe -add -c t.cer -s -r localMachine root
不。
因此,如果您希望在.NET中导入证书,则相应的代码可能如下所示
using System;
using System.Security.Cryptography.X509Certificates;
namespace AddCertToRootStore {
class Program {
static void Main (string[] args) {
X509Store store = new X509Store (StoreName.Root,
StoreLocation.LocalMachine);
store.Open (OpenFlags.ReadWrite);
X509Certificate2Collection collection = new X509Certificate2Collection();
X509Certificate2 cert = new X509Certificate2 (@"C:\Oleg\t.cer");
byte[] encodedCert = cert.GetRawCertData();
Console.WriteLine ("The certificate will be added to the Root...");
store.Add (cert);
Console.WriteLine("Verify, that the certificate are added successfully");
Console.ReadKey ();
Console.WriteLine ("The certificate will be removed from the Root");
store.Remove (cert);
store.Close ();
}
}
}
https://stackoverflow.com/questions/4196997
复制相似问题