Ejemplo n.º 1
0
        private void SelectCert(X509Certificate2 cert)
        {
            txtCert.Text           = CertificateHelper.CertificateName(cert);
            selectedCertificate    = cert;
            btnCertActions.Enabled = true;

            issuerCertificate = null;
            try
            {
                var chain = new X509Chain();
                chain.Build(selectedCertificate);

                if (chain.ChainElements.Count > 1)
                {
                    issuerCertificate = chain.ChainElements[1].Certificate;

                    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                    store.Open(OpenFlags.ReadOnly);
                    var issuerWithPrivateKey = store.Certificates.Find(X509FindType.FindByThumbprint, issuerCertificate.Thumbprint, true).OfType <X509Certificate2>().Where(c => c.HasPrivateKey).FirstOrDefault();
                    store.Close();

                    if (issuerWithPrivateKey != null)
                    {
                        issuerCertificate = issuerWithPrivateKey;
                    }
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
        }
Ejemplo n.º 2
0
 private void SelectCA(X509Certificate2 ca)
 {
     txtCA.Text = CertificateHelper.CertificateName(ca);
     selectedCA = ca;
 }