java中的网络通信加密 [英] network communication encryption in java

查看:126
本文介绍了java中的网络通信加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个朋友和我正在使用一个客户端/服务器架构的Java游戏。
它运行良好,但我遇到了一个问题。
我们使用TCP套接字来实现服务器和客户端之间的联网。
我们的网络协议没有加密,只能被一个谁看不懂的人读取。



我们考虑过如何应用某种加密技术来隐藏登录信息,并阻止人们编写自己的客户端。但是,添加/减少字节的基本事情似乎很容易找出。



通常用于加密游戏网络通信(或至少是游戏登录信息)的方法是什么? ?并且在java中编写了服务器和客户端,有没有什么有用的java库?

解决方案

使用公钥加密(RSA for示例),并实现类似于 SSL握手,或者当然使用SSL - 这里你可以看到一个例子



这是一个简化的顺序:




  • 服务器将他的公共RSA密钥发送给客户端

  • <客户端生成对称密钥(例如使用AES)
  • 客户端使用服务器的公钥加密对称密钥并将其发送到服务器

  • 服务器解密接收到的对称密钥



现在客户端和服务器都有一个密钥,没有人窃听可以知道。然后使用该密钥加密所有数据。


A friend and me are working on a Java Game with a client/server - architecture. It is working well, but i ran into a problem. We use TCP Sockets for networking between server and client. Our network protocol isnt encrypted and can just be read by anone who bothers to watch the stream.

We thought about how we could apply some kind of cryptography to it to hide login information and prevent people to write their own clients. But basic things like adding/substracting bytes seems pretty easy to figure out.

What are the usual methods used to encrypt network communication for games( or at least game login information )? And having written the server and client in java, are there any useful java libraries?

解决方案

Use public-key encryption (RSA for example) and implement something like the SSL Handshake, or of course use SSL - here you can see an example.

Here's a simplified sequence:

  • the server sends his public RSA key to the client
  • the client generates a symmetric key (using AES for example)
  • the client encrypts the symmetric key with the server's public key and sends it to the server
  • the server decrypts the received symmetric key

Now both the client and the server have a key which no one eavesdropping can know. Then use that key to encrypt all data.

这篇关于java中的网络通信加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆