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("結束");


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM