简体   繁体   English

Socket.ReceiveAsync和SslStream

[英]Socket.ReceiveAsync and SslStream

It seems that I cannot get the benefit of ReceiveAsync when using SslStream since I will have to do the reading through SslStream, which only supports the Begin* End* async model. 似乎在使用SslStream时无法获得ReceiveAsync的好处,因为我将不得不通过SslStream进行读取,SslStream仅支持Begin * End *异步模型。

Is it possible to just use SslStream until authentication is done, and from then on just access the socket directly? 是否可以仅使用SslStream直到完成身份验证,然后才直接访问套接字? This means I would have to find out what level of security was negotiated, and then apply the correct encryption/decryption to the buffers myself. 这意味着我必须找出协商的安全级别,然后自己对缓冲区应用正确的加密/解密。 Encryption before sending, and decryption after receiving. 发送前进行加密,接收后进行解密。

Is this doable? 这可行吗?

Thanks! 谢谢!

SslStream is giving you privacy + server auth, and depending on whether you use ClientCertificates, Client authentication as well. SslStream为您提供隐私+服务器身份验证,并取决于您是否使用ClientCertificates和Client身份验证。 You cannot use the socket directly, because once the SSL session is established, the key exchange would have bound the encryption and other algorithms to the session, and it is not possible to duplicate that in code. 您不能直接使用套接字,因为一旦建立了SSL会话,密钥交换将把加密和其他算法绑定到该会话,并且无法在代码中复制该套接字。

Anyway, SslStream.Begin/End methods give you the async functionality you need. 无论如何,SslStream.Begin / End方法为您提供了所需的异步功能。 Why do you need to fall back to Socket.SendAsync/ReceiveAsync() ? 为什么需要使用Socket.SendAsync / ReceiveAsync()?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM