Get list of certificates from the certificate store in C#

Kottan picture Kottan · Jul 30, 2009 · Viewed 100.6k times · Source

For a secure application I need to select a certificate in a dialog. How can I access certificate store or a part of it (e.g. storeLocation="Local Machine" and storeName="My") using C# and get a collection of all certificates from there? Thanks in advance for your help.

Answer

acejologz picture acejologz · May 17, 2011
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

store.Open(OpenFlags.ReadOnly);

foreach (X509Certificate2 certificate in store.Certificates){
    //TODO's
}