使用WSE时,客户端通过c#导入证书

    技术2022-05-12  21

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

                }

            }    }}


    最新回复(0)