using System.Security.Cryptography.X509Certificates; // Load the certificate X509Certificate2 cert = new X509Certificate2(@"C:\path\to\certificate.cer"); // Create a chain object and set the policy X509Chain chain = new X509Chain(); chain.ChainPolicy = new X509ChainPolicy() { RevocationMode = X509RevocationMode.NoCheck }; // Build the chain bool isValid = chain.Build(cert); // Check if the certificate is valid if (isValid) { Console.WriteLine("Certificate chain is valid"); } else { Console.WriteLine("Certificate chain is not valid"); }
using System.Security.Cryptography.X509Certificates; // Load the certificate X509Certificate2 cert = new X509Certificate2(@"C:\path\to\certificate.cer"); // Create a chain object X509Chain chain = new X509Chain(); // Build the chain chain.Build(cert); // Get the chain status X509ChainStatus[] status = chain.ChainStatus; // Print the status of each certificate in the chain foreach (X509ChainStatus s in status) { Console.WriteLine(s.StatusInformation); }In this example, we again load a certificate from a file. We then create a new X509Chain object and call the Build method to build the chain. We can then get the status of each certificate in the chain by accessing the ChainStatus property on the chain object. These examples use the System.Security.Cryptography.X509Certificates namespace, which is part of the .NET Framework.