Created
April 11, 2013 13:17
-
-
Save sebnilsson/5363282 to your computer and use it in GitHub Desktop.
Get X509Certificate2 from Store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static X509Certificate2 GetX509Certificate2(string thumbprint) | |
{ | |
var store = new X509Store(StoreLocation.LocalMachine); | |
store.Open(OpenFlags.ReadOnly); | |
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly); | |
var certificates = store.Certificates.Cast<X509Certificate2>().ToList(); | |
var cert = | |
certificates.FirstOrDefault( | |
x => x.Thumbprint.Equals(thumbprint, StringComparison.InvariantCultureIgnoreCase)); | |
store.Close(); | |
return cert; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment