0

есть адрес веб-сайта к примеру https://ru.stackoverflow.com. Как можно проверить сертификат этого сайта?

2

1 ответ 1

1

Вот код проверки сертификата (взят отсюда):

 static void Main(string[] args)
    {
        String url = "https://www.example.com";
        HttpWebRequest request = WebRequest.CreateHttp( url );
        request.ServerCertificateValidationCallback +=  ServerCertificateValidationCallback;
        using( HttpWebResponse response = (HttpWebResponse)request.GetResponse() ) { }
        Console.WriteLine("End");
        Console.ReadKey();
    }

    private static bool ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
        if (sslPolicyErrors == SslPolicyErrors.None)
        {
            Console.WriteLine("Certificate OK");
            return true;
        }
        else
        {
            Console.WriteLine("Certificate ERROR");
            return false;
        }
    }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.