abmv
abmv

Reputation: 7098

Check if end user certificate installed in windows keystore?

Is there any way to check in C# if the PKI end user certificate is installed in the user windows keystore (Personal)? (An exception would do?) I would be passing some attribute like Name.

Upvotes: 8

Views: 5277

Answers (1)

KMeda
KMeda

Reputation: 473

You can use the X509Store class to search for certificates on the system. Below code sample finds a certificate by subject name of "XYZ" in the Current User's Personal Store.

System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly); // Dont forget. otherwise u will get an exception.
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName,"XYZ",true);
if(certs.Count > 0)
{
    // Certificate is found.
}
else
{
    // No Certificate found by that subject name.
}

Upvotes: 9

Related Questions