0

服务器

 decCipher.init(Cipher.DECCRYPT_MODE, secretKey);
     ois = new ObjectInputStream(new CipherInputStream(socket.getInputStream(),decCipher));
     encCipher.init(Cipher.ENCRYPT_MODE, secretKey);
     out = new ObjectOutputStream(new CipherOutputStream(socket.getOutputStream(),encCipher));

客户端(不同的应用程序):

e

ncCipher.init(Cipher.ENCRYPT_MODE, secretKey);
obj_out = newObjectOutputStream(new CipherOutputStream(socket.getOutputStream(),encCipher));
 decCipher.init(Cipher.DECRYPT_MODE, secretKey);
 obj_in = new ObjectInputStream(new CipherInputStream(socket.getInputStream(),decCipher)

服务器应用程序中的 Ois 在创建流时引发异常。如何解决?当这没有包含在密码流中时,一切正常。

异常不会仅在创建时引发new ObjectInputStream,而是冻结 10 秒(超时),当达到超时限制时会引发异常。

例外:

at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2298)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2767)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:798)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:298)
4

1 回答 1

0

您需要使用两种不同的Cipher对象,一种用于加密,一种用于解密。考虑将Cipher对象附加到CipherInputStream后的模式ENCRYPT_MODE

于 2012-05-15T23:41:43.730 回答