[英]Java serializable security over TCP
我有一個TCP/IP
聊天應用程序,它來回發送包含消息的int類型和String消息的ChatMessage
對象。
我的問題是:如何使它更安全?
謝謝!
我可以想到兩種方法: CipherOutputStream
和SSLSocket
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
或者,您可以使用SSL: 如何進行SSL套接字編程
假設您需要一個提供數據Confidentiality
, Integrity
和User Authenticity
的安全系統,這就是使用偽代碼進行User Authenticity
。 ( http://en.wikipedia.org/wiki/Information_security )。 無論如何,這些都是對安全聊天系統的一般要求。
現在,您可以學習這些概念,並且它們很容易實現。 對於算法,最受歡迎的是:
這兩種算法都有可用的Java實現,請查看Bouncy Castle加密API軟件包。
注意:如果您使用的是Web應用程序,並且只需要安全地傳輸消息,則可以按照注釋中的建議使用SSL 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.