我有這樣的代碼,通過網絡發送encryted數據:CipherOutputStream通過套接字的Java
s = new Socket(serverAddress, serverPort);
is = s.getInputStream();
os = s.getOutputStream();
Cipher decryptCipher = Cipher.getInstance("RSA");
decryptCipher.init(Cipher.DECRYPT_MODE, ClientSocket.clientPrivateKey);
cis = new CipherInputStream(is,decryptCipher);
Cipher encryptCipher = Cipher.getInstance("RSA");
encryptCipher.init(Cipher.ENCRYPT_MODE, this.serverPublicKey);
cos = new CipherOutputStream(os,encryptCipher);
此代碼的工作,但是當我嘗試使用CipherOutputStream
通過網絡發送加密數據,該數據是不直到我打電話cos.close()
,但如果我關閉了流,我關閉了網絡連接。用CipherOutputStream
發送加密數據的正確過程是什麼?