当前位置: 首页>>代码示例>>C#>>正文


C# SslStream.EndAuthenticateAsServer方法代码示例

本文整理汇总了C#中SslStream.EndAuthenticateAsServer方法的典型用法代码示例。如果您正苦于以下问题:C# SslStream.EndAuthenticateAsServer方法的具体用法?C# SslStream.EndAuthenticateAsServer怎么用?C# SslStream.EndAuthenticateAsServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SslStream的用法示例。


在下文中一共展示了SslStream.EndAuthenticateAsServer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoHandshake

 protected override bool DoHandshake(SslStream clientSslStream, SslStream serverSslStream)
 {
     using (X509Certificate2 certificate = Configuration.Certificates.GetServerCertificate())
     {
         IAsyncResult a1 = clientSslStream.BeginAuthenticateAsClient(certificate.GetNameInfo(X509NameType.SimpleName, false), null, null);
         IAsyncResult a2 = serverSslStream.BeginAuthenticateAsServer(certificate, null, null);
         if (WaitHandle.WaitAll(new[] { a1.AsyncWaitHandle, a2.AsyncWaitHandle }, TestConfiguration.PassingTestTimeoutMilliseconds))
         {
             clientSslStream.EndAuthenticateAsClient(a1);
             serverSslStream.EndAuthenticateAsServer(a2);
             return true;
         }
         return false;
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:SslStreamStreamToStreamTest.cs

示例2: TestAsyncBasic

		public void TestAsyncBasic()
		{
			var listener = new TcpListener(IPAddress.Loopback, 0);
			listener.Start(5);
			var ep = (IPEndPoint)listener.LocalEndpoint;

			Console.WriteLine("Server> waiting for accept");

			listener.BeginAcceptTcpClient((IAsyncResult ar) =>
			{
				var client = listener.EndAcceptTcpClient(ar);

				var sslStream = new SslStream(client.GetStream(), false);
				Console.WriteLine("Server> authenticate");

				sslStream.BeginAuthenticateAsServer(_ctx.ServerCertificate, async (ar2) =>
				{
					sslStream.EndAuthenticateAsServer(ar2);

					Console.WriteLine("Server> CurrentCipher: {0}", sslStream.Ssl.CurrentCipher.Name);
					Assert.AreEqual("AES256-GCM-SHA384", sslStream.Ssl.CurrentCipher.Name);

					var buf = new byte[256];
					await sslStream.ReadAsync(buf, 0, buf.Length);
					Assert.AreEqual(clientMessage.ToString(), buf.ToString());

					await sslStream.WriteAsync(serverMessage, 0, serverMessage.Length);

					sslStream.Close();
					client.Close();

					Console.WriteLine("Server> done");
				}, null);
			}, null);

			var evtDone = new AutoResetEvent(false);

			var tcp = new TcpClient(AddressFamily.InterNetwork);
			tcp.BeginConnect(ep.Address.ToString(), ep.Port, (IAsyncResult ar) =>
			{
				tcp.EndConnect(ar);

				var sslStream = new SslStream(tcp.GetStream());
				Console.WriteLine("Client> authenticate");

				sslStream.BeginAuthenticateAsClient("localhost", async (ar2) =>
				{
					sslStream.EndAuthenticateAsClient(ar2);

					Console.WriteLine("Client> CurrentCipher: {0}", sslStream.Ssl.CurrentCipher.Name);
					Assert.AreEqual("AES256-GCM-SHA384", sslStream.Ssl.CurrentCipher.Name);

					await sslStream.WriteAsync(clientMessage, 0, clientMessage.Length);

					var buf = new byte[256];
					await sslStream.ReadAsync(buf, 0, buf.Length);
					Assert.AreEqual(serverMessage.ToString(), buf.ToString());

					sslStream.Close();
					tcp.Close();

					Console.WriteLine("Client> done");

					evtDone.Set();
				}, null);
			}, null);

			evtDone.WaitOne();
		}
开发者ID:yaobos,项目名称:openssl-net,代码行数:69,代码来源:TestSSL.cs


注:本文中的SslStream.EndAuthenticateAsServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。