服务器
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));
客户(不同的申请):
ë
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)
答案 0 :(得分:0)
您需要使用两个不同的Cipher
个对象,一个用于加密,一个用于解密。在将Cipher
放入CipherInputStream
之后,考虑ENCRYPT_MODE
附加到{{1}}对象的模式。