小编use*_*929的帖子

SSL客户端/服务器相互认证

您好我正在尝试在C#中使用服务器和客户端证书进行相互身份验证的ssl客户端/服务器通信.设法只使用服务器证书进行ssl通信,在客户端我使用这样的:

TcpClient client = new TcpClient(machineName, port);
//Create an SSL stream that will close the client's stream.
   SslStream sslStream = new SslStream(
   client.GetStream(),
   false,
   new RemoteCertificateValidationCallback(ValidateServerCertificate),
   null
   );
try
{
    // The server name must match the name on the server certificate.
    sslStream.AuthenticateAsClient(serverName);
}
catch (AuthenticationException e)
{
    Console.WriteLine("Exception: {0}", e.Message);
    if (e.InnerException != null)
    {
        Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
    }
    Console.WriteLine("Authentication failed - closing the connection.");
    client.Close();
    return;
} 
Run Code Online (Sandbox Code Playgroud)

我想我需要使用

AuthenticateAsClient(string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Run Code Online (Sandbox Code Playgroud)

方法,我是谁?有谁可以告诉我如何使用它与所有的东西?甚至在服务器端,或指向我一个基本的例子? …

c# authentication ssl client

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

authentication ×1

c# ×1

client ×1

ssl ×1