[英]Java serializable security over TCP
I have a TCP/IP
chat application that sends back and forth ChatMessage
objects that hold the int type and String message of a message. 我有一个
TCP/IP
聊天应用程序,它来回发送包含消息的int类型和String消息的ChatMessage
对象。
My question is: How can I make it more secure? 我的问题是:如何使它更安全?
Thank you! 谢谢!
There are two ways that I can think up of: CipherOutputStream
and SSLSocket
我可以想到两种方法:
CipherOutputStream
和SSLSocket
CipherOutputStream : CipherOutputStream :
byte[] keyBytes = "1234123412341234".getBytes();
final byte[] ivBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; //example
final SecretKey key = new SecretKeySpec(keyBytes, "AES");
final IvParameterSpec IV = new IvParameterSpec(ivBytes);
final Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, key, IV);
//assuming your Socket is called "socket"
CipherOutputStream cstream = new CipherOutputStream(socket.getOutputStream(), cipher);
...
//code to write ChatMessage object
OR, you can use SSL: how to do ssl socket programming 或者,您可以使用SSL: 如何进行SSL套接字编程
Here's how you do it in pseudocode, assuming you need a secure system providing data Confidentiality
, Integrity
and User Authenticity
. 假设您需要一个提供数据
Confidentiality
, Integrity
和User Authenticity
的安全系统,这就是使用伪代码进行User Authenticity
。 ( http://en.wikipedia.org/wiki/Information_security ). ( http://en.wikipedia.org/wiki/Information_security )。 These are the general requirements for a secure chat system anyways.
无论如何,这些都是对安全聊天系统的一般要求。
Now you can go learn these concepts and they fairly straightforward to implement. 现在,您可以学习这些概念,并且它们很容易实现。 For Algorithms, the most popular used are:
对于算法,最受欢迎的是:
Both of these algorithms have Java implementations available, checkout the Bouncy Castle crypto API package. 这两种算法都有可用的Java实现,请查看Bouncy Castle加密API软件包。
Note: If you are using a web application, and just need to securely transfer the messages, you can use SSL as someone suggested in the comments. 注意:如果您使用的是Web应用程序,并且只需要安全地传输消息,则可以按照注释中的建议使用SSL 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.