Пример кода на языке C#.
Код: Выделить всё
// The following method is invoked by the RemoteCertificateValidationDelegate.
public static bool ValidateServerCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
Console.WriteLine("Certificate error: {0}", sslPolicyErrors);
// Do not allow this client to communicate with unauthenticated servers.
return false;
}
Код: Выделить всё
X509Store store = new X509Store("Root", StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509ChainElement rootElement = chain.ChainElements[chain.ChainElements.Count - 1]; //To get the root of the chain
X509Certificate2 rootCert = rootElement.Certificate;
foreach (X509Certificate2 cert in store.Certificates)
{
// Compare the thumbprint of each certificate
if (cert.Thumbprint.Equals(rootCert.GetCertHashString(), StringComparison.OrdinalIgnoreCase))
{
// Certificate found
return true;
}
}
return false;
Подробнее здесь: https://stackoverflow.com/questions/792 ... ent-in-the