问题描述
使用以下 TcpClient 代码,sslStream 的身份验证正常。
X509Certificate serverCertificate = new X509Certificate("PathToMyCert\MyCert.pfx","CertPassword");
TcpListener listener = new TcpListener(IPAddress.Any,9001);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
SslStream sslStream = new SslStream(client.GetStream(),false);
sslStream.AuthenticateAsServer(serverCertificate,false,SslProtocols.Tls12,true);
Console.WriteLine("Authenticated...");
但是,使用套接字的等效代码,我得到一个 System.NotSupportedException:“服务器模式 SSL 必须使用具有关联私钥的证书。”在 sslStream.AuthenticateAsServer 上,但它是相同的证书等。下面是我的套接字代码的近似值。关于我做错了什么的任何想法?
X509Certificate serverCertificate = new X509Certificate("PathToMyCert\MyCert.pfx","CertPassword");
IPEndPoint _endPoint = new IPEndPoint(IPAddress.Any,9001);
Socket listener = new Socket(SocketType.Stream,ProtocolType.Tcp);
listener.Bind(_endPoint);
listener.Listen(10);
Socket socket = listener.Accept();
NetworkStream innerStream = new NetworkStream(socket);
SslStream sslStream = new SslStream(innerStream,false);
sslStream.AuthenticateAsServer(serverCertificate,true);
Console.WriteLine("Authenticated...");
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)