Search code examples
c#.netcryptographyx509certificate2

Unable to get a certificate from store in c# by common name


In .Net 4.0 I have been unable to get a certificate from a custom store using the find method of the X509Store. Using the following code:

X509Store store = new X509Store(storeName, StoreLocation.CurrentUser);

store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, commonName,false);

Solution

  • Fixed It

    Sorry I had made a basic mistake I had forgotten to make the private key exportable so the crypto apis would not expose the private key to .net once I made the keys exportable the code began to work.