public bool IsContactCertificateInStore(string strContactID)
        {
            bool bRetVal = false;

            X509CertificateStore certStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);

            if (certStore == null)
            {
                throw new Exception("Error opening Local Machine Store");
            }

            if (certStore.OpenRead())
            {
                X509CertificateCollection certColl = certStore.FindCertificateBySubjectName(strContactID);
                if (certColl.Count == 0)
                {
                    bRetVal = false;
                }
                else
                {
                    bRetVal = true;
                }
            }

            // Close the certificate store
            certStore.Close();

            return(bRetVal);
        }
Exemple #2
0
        private void OkBtn_Click(object sender, System.EventArgs e)
        {
            _certificate = null;

            if (_certList.SelectedItems != null && _certList.SelectedItems.Count == 1)
            {
                X509CertificateCollection coll = _store.FindCertificateBySubjectName(_certList.SelectedItems[0].Text);
                if (coll != null && coll.Count == 1)
                {
                    _certificate = coll[0] as X509Certificate;
                }
            }

            this.Close();
            this.DialogResult = DialogResult.OK;
        }
        public X509Certificate GetContactCertificate(string strContactID)
        {
            X509CertificateStore certStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);

            if (certStore == null)
            {
                throw new Exception("Error opening Local Machine Store");
            }

            X509Certificate cert = null;

            if (certStore.OpenRead())
            {
                X509CertificateCollection certColl = certStore.FindCertificateBySubjectName(strContactID);
                if (certColl.Count == 1)
                {
                    cert = certColl[0];
                }
            }

            // Close the certificate store
            certStore.Close();
            return(cert);
        }