Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am attempting to enumerate certificate stores on my server and get information about each certificate. The code works correctly except it is missing all certificates found in the "Intermediate Certification Authorities" store.

string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority", "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
              for (int x = 0; x < stores.Length; x++)
              {
                  X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

                  store.Open(OpenFlags.ReadOnly);

                  foreach (X509Certificate2 mCert in store.Certificates)
                  {
                            //handle certificates
                      }

              }
Posted

1 solution

I ended up getting it to work, for some reason for every store except "CertificateAuthority" you can pass the name as done in my original code (stores[x]). For "CertificateAuthority" I had to explicitly pass "Store.CertificateAuthority".

C#
//Old Code
string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority", "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

//New Code
X509Store store2= new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900