// Load the certificate and intermediate certificates X509Certificate2 certificate = new X509Certificate2("path/to/certificate.pfx"); X509Certificate2Collection intermediateCertificates = new X509Certificate2Collection(); intermediateCertificates.Add(new X509Certificate2("path/to/intermediate1.cer")); intermediateCertificates.Add(new X509Certificate2("path/to/intermediate2.cer")); // Build the certificate chain X509Chain chain = new X509Chain(); chain.ChainPolicy.ExtraStore.AddRange(intermediateCertificates); chain.Build(certificate); // Check the result bool isValid = chain.ChainStatus.Length == 0;
// Load the certificate X509Certificate2 certificate = new X509Certificate2("path/to/certificate.pfx"); // Build the certificate chain X509Chain chain = new X509Chain(); chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority; chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck; bool chainBuilt = chain.Build(certificate); // Check the result bool isValid = chain.ChainStatus.Length == 0;In both examples, we create an instance of X509Chain and call its Build method to build a certificate chain. We then check the results of the chain building process to determine whether the certificate is valid. The package library used in both examples is System.Security.Cryptography.X509Certificates.