using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Security.Cryptography.X509Certificates;
namespace CertSetup{ public partial class frmCert : Form { public frmCert() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
OpenFileDialog dia = new OpenFileDialog(); if (dia.ShowDialog() == DialogResult.OK) { X509Certificate2 cert = new X509Certificate2(dia.FileName);
X509Store storeMy = new X509Store(StoreName.My, StoreLocation.LocalMachine); storeMy.Open(OpenFlags.ReadWrite);
//如果证书不存在则加入 if (!storeMy.Certificates.Contains(cert)) { storeMy.Add(cert);
} storeMy.Close();
}
} }}