2010-01-18 81 views
4

我有一個富客戶端應用程序正在連接到一組支持Web服務的連接受SSL保護的連接。我需要確定用於實際SSL流的加密的「強度」,以將此信息顯示給最終用戶。如何確定SSL連接的「強度」

我的理解是,客戶端和服務器將與不同級別的加密(40,56,128,256)協商它們(SSL/TLS)之間的對稱加密方法。有沒有什麼辦法可以檢測到C#代碼中的HttpWebRequest/ServicePoint/other使用哪種模式?

回答

1

這在擴展@亞歷克斯的帖子,明顯增加自己的錯誤處理

 System.Net.Sockets.TcpClient TC = new System.Net.Sockets.TcpClient(); 
     TC.Connect("mail.google.com", 443); 
     using (System.Net.Security.SslStream Ssl = new System.Net.Security.SslStream(TC.GetStream())) 
     { 
      Ssl.AuthenticateAsClient("mail.google.com"); 
      Console.WriteLine(Ssl.CipherAlgorithm); 
      Console.WriteLine(Ssl.CipherStrength); 
     } 
     TC.Close(); 

我不認爲你可以直接訪問從Web服務的SSL的信息,你將不得不使用這個助手代碼直接與主持人交談。

1

既然你已經建立了SslStream stream,你可以使用以下命令:

stream.CipherAlgorithm //to get the algorithm that is used 
stream.CipherStrength //to get the strength of the cipher algorithm 

你可以找到更多信息here