证书安装安全警告解决方法?

我有一些C#4.0代码尝试将CA(.der编码)证书安装到当前(我的)用户的“受信任的根证书颁发机构”存储中。 我的小控制台应用程序默默地对其他商店运行,但是对于这个商店,会出现一个GUI弹出窗口“您即将从证书颁发机构安装证书… Windows无法validation证书是否实际来自…..你是否想要安装这个证书吗?“

此消息框是一个问题,因为我们的想法是使用MSI自动部署应用程序,并在正确的位置静默获取正确的证书。 拥有模态框将导致自动部署失败。

如何在没有部署中断消息框的情况下完成此安装?

它听起来不合逻辑,但是没有警告你应该将证书不是添加到当前用户的根证书存储区,而是添加到本地计算机的Root。 您可以轻松validation

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 (); } } }