Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 632
abmv Avatar asked Jun 23 '11 09:06

abmv


1 Answers

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.
}
like image 88
KMeda Avatar answered Nov 09 '22 11:11

KMeda