Check if the end user certificate is installed in the Windows keystore?

Is there a way to check C # if the PKI end-user certificate is installed in the keystore (Personal) user window? (Will there be an exception?) I would pass some attribute, for example Name.

+6
source share
1 answer

You can use the X509Store class to search for certificates in the system. Below the sample code finds a certificate by the name of the subject "XYZ" in the personal store of the current user.

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. } 
+6
source

Source: https://habr.com/ru/post/891194/


All Articles