从文本(char *)获取数据的最佳方法

发布于 2024-10-04 10:44:42 字数 154 浏览 0 评论 0原文

嘿, 我通过 TCP 和 UDP 从客户端向服务器发送消息,而服务器是用 C++ 编写的。我想知道什么是最好的、必须安全的发送方式,例如,如果我想发送登录数据:电子邮件、密码和 IP。在消息中发送它并读取服务器中的数据的最佳方式是什么,而该数据存储在 char * 中。

谢谢。

Hey,
I'm sending messages via TCP and UDP from clients to the server while the server written in C++. I'm wondering what would be the best, must secure way to send, for example, if I want to send login data: email, password and IP. What would be the best way to send it in a message ang read the data in the server, while this data is stored in char *.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巡山小妖精 2024-10-11 10:44:42

这实际上与 C++ 没有任何关系。您问的是有关信息安全的一般性问题。您想要通过 TCP 或 UDP 发送包含敏感信息(电子邮件地址、密码和 IP)的信息。为此,您需要使用密码学。

密码学是一个复杂的领域,除非您非常了解自己在做什么,否则您不应该尝试推出自己的协议。相反,您应该避免使用 UDP(因为很难通过 UDP 正确进行加密),而只需使用 TCP 上的 SSL。

要从 C++ 执行此操作,您可以使用 OpenSSL 套接字库。客户端和服务器都与库链接。如果您需要一点帮助,可以使用 sslwrap 进行调试,这是一个命令行工具,允许您使用来自客户端和客户端的明文套接字。服务器,但将未加密的数据封装在 SSL TCP 连接内。

This doesn't really have anything to do with C++. You are asking a generic question about information security. You want to send information via TCP or UDP that includes sensitive information (email address, password, and IP). For this you need to use cryptography.

Cryptography is a complicated area where you should not try to roll your own protocols unless you know a lot about what you are doing. Instead, you should avoid UDP (because it is VERY hard to do crypto properly over UDP) and simply use SSL over TCP.

To do this from C++ you can use the OpenSSL sockets library. Both the client and the server link with the library. If you want a little help, you can debug using sslwrap, a command-line tool that allows you to use cleartext sockets from your client & server, but have the unencrypted data wrapped inside an SSL TCP connection.

似最初 2024-10-11 10:44:42

正如另一位发帖者所说,不要担心 C++;使用 SSL 或 TLS。这意味着您需要为服务器获取一个证书,如果您获得商业证书,则需要花费 50 到 1500 美元,或者您可以从您自己建立的 Intranet 证书颁发机构制作自己的证书。

此措施将对通信进行加密,并确保您的客户端实际上是在与真实服务器“对话”,而不是冒名顶替者。但是,如果您还需要对客户端进行身份验证,那么您将需要第二个证书(准确地说,可能每台客户端计算机一个)。如果这对于您的客户端需求来说太重了,那么请考虑使用 HMAC 来帮助确定授权客户端和冒名顶替者。

As another poster stated, don't worry about C++; use SSL or TLS. This means you will need to acquire a certificate for the server, and that will cost you between $50 and $1500 dollars if you get a commercial one, or you can make your own from a intranet certificate authority that you establish yourself.

This measure will encrypt the communication, and ensure that your client is actually "talking" to the authentic server, not an imposter. However, if you need the client to also be authenticated, then you will need a second certificate (possibly one per client machine, to be precise). If that is too heavy-weight for your client needs, then consider using HMAC to help determine an authorized client from an imposter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文