【发布时间】:2014-04-11 17:00:24
【问题描述】:
我有这段代码可以通过网络发送加密数据:
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 发送加密数据的正确流程是什么?
【问题讨论】:
标签: java sockets encryption outputstream