你好我正在嘗試在C#中使用服務器和客戶端證書進行雙向認證的SSL客戶端/服務器通信。受管辦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;
}
我想我需要使用
AuthenticateAsClient(string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
方法,我是corrent?任何人都可以告訴我如何使用它,甚至在服務器端,或者指向一個基本的例子?
非常感謝。
我可以問你爲什麼沒有嘗試過使用WCF框架?他們有相互認證的選項,併爲你做了很多繁重的工作。 [WCF文檔](http://msdn.microsoft.com/en-us/netframework/aa663324) – Jay