X509Certificate2 cert = new X509Certificate2("myCert.pfx", "myPassword"); string hash = cert.GetCertHashString(); Console.WriteLine("Cert hash: " + hash);
X509Certificate2Collection certColl = new X509Certificate2Collection(); certColl.Import("myCerts.p7b"); foreach (X509Certificate2 cert in certColl) { string hash = cert.GetCertHashString(); Console.WriteLine("Cert hash: " + hash); }In this example, we create a collection of X509Certificate2 objects by importing a PKCS#7 (P7B) file that contains multiple certificates. We then iterate over the collection and call the GetCertHashString method on each certificate to obtain its hash value, which is printed to the console. Package/Library: System.Security.Cryptography.X509Certificates.