Skip to content

Instantly share code, notes, and snippets.

@RichardSlater
Created March 5, 2014 22:01
Show Gist options
  • Save RichardSlater/9377557 to your computer and use it in GitHub Desktop.
Save RichardSlater/9377557 to your computer and use it in GitHub Desktop.
X.509 Certificate Repository
public class X509CertificateRepository {
public IEnumerable<X509Certificate2> FindBySubjectName(StoreName storeName, StoreLocation storeLocation, string subject) {
  var store = new X509Store(storeName, storeLocation);
  store.Open(OpenFlags.ReadOnly);
  var certificates = store.Certificates.Find(X509FindType.FindBySubjectName, subject, validOnly: false);
  foreach (var certificate in certificates) {
   yield return certificate;
  }
  store.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment