c# Возвращаем сертификат из хранилища Windows сертификатов / c# get certificate from windows store

public static X509Certificate2 GetCertificateFromStore(string certName)
        {
            X509Store store = new X509Store(StoreLocation.CurrentUser);
            try
            {
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection certCollection = store.Certificates;
                X509Certificate2Collection currentCerts = certCollection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
                X509Certificate2 o = currentCerts[0];
                X509Certificate2Collection signingCert = currentCerts.Find(X509FindType.FindBySubjectName, certName, false);
                if (signingCert.Count == 0)
                    return null;
                return signingCert[0];
            }
            finally
            {
                store.Close();
            }

        }

2 comments:

  1. Спасибо! Все прекрасно, понятно

    ReplyDelete
    Replies
    1. забирайте на здоровье :)

      Delete

Note: only a member of this blog may post a comment.