C# 简单的客户端/服务器,TCP/IP 加密消息流,SSL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/937459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:45:08  来源:igfitidea点击:

Simple client/server, TCP/IP encrypting the message stream, SSL

c#sslclienttcp

提问by flavour404

Writing a little TCP/IP client server app. Basically it creates a server, and then you can create several different clients and set up a bit of a chat session. What I am wondering is there is any way to incorporate, using standard .net libraries some form of encryption?

编写一个小的 TCP/IP 客户端服务器应用程序。基本上它会创建一个服务器,然后您可以创建几个不同的客户端并设置一些聊天会话。我想知道有什么方法可以合并,使用标准的 .net 库某种形式的加密?

m_mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

m_mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

Is there any way of speficying tcp using rsa?

有没有办法使用 rsa 指定 tcp?

Or would you (me that is) have to write some custom libaries to do key exchange and then encrypt the subsequent chat messages? I have done that before for uni but that was in java but I know it would'nt be hard to convert them. Just trying not to have to reinvent the wheel...

或者您(我就是)是否必须编写一些自定义库来进行密钥交换,然后加密后续的聊天消息?我之前为 uni 做过这件事,但那是在 Java 中,但我知道转换它们并不难。只是尽量不要重新发明轮子......

Or what about utilising a ssl?

或者使用 ssl 怎么样?

Thanks, Ron.

谢谢,罗恩。

回答by Reed Copsey

The simplest way to encrypt your communication would be to just wrap the entire socket stream in a SslStream.

加密通信的最简单方法是将整个套接字流包装在SslStream 中

This is made to work directly with TcpClient/TcpListener, so it's very easy to encrypt a data stream using this.

它可以直接与 TcpClient/TcpListener 一起使用,因此使用它加密数据流非常容易。

回答by sybreon

Just wrap it around a library, or alternatively, an SSL tunnel application.

只需将它包装在一个库中,或者,一个 SSL 隧道应用程序。