C#程序自动安装数字证书

using System.Security.Cryptography.X509Certificates;

 

MessageBox.Show("开始");

 

//添加个人证书

X509Certificate2 certificate = new X509Certificate2(Application.StartupPath + \\cert.pfx","证书密码");
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
store.Remove(certificate);   //可省略
store.Add(certificate);
store.Close();

 

//安装CA的根证书到受信任根证书颁发机构
certificate = new X509Certificate2(Application.StartupPath + "\\CA.cer");
store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Remove(certificate);   //可省略
store.Add(certificate);
store.Close();

           
MessageBox.Show("结束");

posted @ 2016-11-23 10:00  天王星天  阅读(4472)  评论(0编辑  收藏  举报