Пример #1
0
        private void SelectCertButton_Click(object sender, EventArgs e)
        {
            CertificateSelectionDialog dlg = new CertificateSelectionDialog();

            X509Certificate2 selectedCert = null;

            if (CertificateCombo.SelectedIndex > -1 &&
                CertificateCombo.SelectedIndex < certificates.Count)
            {
                selectedCert = certificates[CertificateCombo.SelectedIndex];
            }

            foreach (X509Certificate2 cert in certificates)
            {
                string cn = ExtractDNField(cert.Subject, "CN");
                if (cn == null)
                {
                    cn = cert.Subject;
                }
                string email    = ExtractDNField(cert.Subject, "E");
                string org      = ExtractDNField(cert.Subject, "O");
                string issuerCN = ExtractDNField(cert.Issuer, "CN");
                string valid    = cert.NotAfter.ToShortDateString();
                string hash     = cert.GetCertHashString();

                ListViewItem lvi = new ListViewItem(new string[] { cn, email, org, issuerCN, valid, hash });
                lvi.Selected = cert == selectedCert;
                dlg.CertificateList.Items.Add(lvi);
            }

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (dlg.CertificateList.SelectedIndices.Count == 1)
                {
                    CertificateCombo.SelectedIndex = dlg.CertificateList.SelectedIndices[0];
                }
            }
        }
Пример #2
0
        private void SelectCertButton_Click(object sender, EventArgs e)
        {
            CertificateSelectionDialog dlg = new CertificateSelectionDialog();

            X509Certificate2 selectedCert = null;
            if (CertificateCombo.SelectedIndex > -1 &&
                CertificateCombo.SelectedIndex < certificates.Count)
            {
                selectedCert = certificates[CertificateCombo.SelectedIndex];
            }

            foreach (X509Certificate2 cert in certificates)
            {
                string cn = ExtractDNField(cert.Subject, "CN");
                if (cn == null)
                {
                    cn = cert.Subject;
                }
                string email = ExtractDNField(cert.Subject, "E");
                string org = ExtractDNField(cert.Subject, "O");
                string issuerCN = ExtractDNField(cert.Issuer, "CN");
                string valid = cert.NotAfter.ToShortDateString();
                string hash = cert.GetCertHashString();

                ListViewItem lvi = new ListViewItem(new string[] { cn, email, org, issuerCN, valid, hash });
                lvi.Selected = cert == selectedCert;
                dlg.CertificateList.Items.Add(lvi);
            }

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (dlg.CertificateList.SelectedIndices.Count == 1)
                {
                    CertificateCombo.SelectedIndex = dlg.CertificateList.SelectedIndices[0];
                }
            }
        }