Search code examples
c#x509certificate

how to get X509Certificate using Friendly Name rather than Thumbprint?


I have a certificate which having Friendly Name as well and I want to get the certificate using Friendly Name rather than Thumbprint. I don't see any method like FindByFriendlyName..., how to do this?

enter image description here

 var thumbprint ="f454......"
 var friendlyName = "ASP.NET Core...."    

 X509Certificate2Collection signingCerts = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
            X509Certificate2Enumerator enumerator = signingCerts.GetEnumerator();

Solution

  • Built-in search can be done only against static fields, that never change for any given certificate. Friendly name is not static, it can be changed for any single certificate unlimited times. Thus, I would STRONGLY recommend to not rely on cert friendly name. EVER.

    you can do manual filtering, by enumerating all certificates and checking for matching certificate, but it is very poor and fragile way.