我可以使用python客户端成功连接服务器,如下所示:
...
sslSock = ssl.wrap_socket(sock, key_file, cert_file, ssl_version=ssl.PROTOCOL_TLSv1)
...
但我无法使用C#连接服务器:
...
byte[] pfxData = File.ReadAllBytes("bob_pfx.pfx");
TcpClient client = new TcpClient(machineName, port);
Stream stream = client.GetStream();
SslStream sslstream = new SslStream(client.GetStream());
X509Certificate2 certificate = new X509Certificate2(pfxData,"", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
X509Certificate2Collection certificateCollection = new X509Certificate2Collection();
certificateCollection.Add(certificate);
try
{
sslstream.AuthenticateAsClient(machineName, certificateCollection, SslProtocols.Tls, true);
}
catch (SystemException ex)
{
Console.WriteLine(ex.Message);
}
...
文件" bob_pfx.pfx"是由这个命令构建的:
openssl pkcs12 -export -out test.pfx -inkey rui.key -in rui.crt
错误信息是:
The authentication or decryption has failed.
我的代码有问题吗? 非常感谢!