CipherOutputStream over a socket java -


i have code send encryted data on network:

s = new socket(serveraddress, serverport); = 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); 

this code works, when try use cipheroutputstream send encrypted data on network, data not sent until call cos.close(), if close stream close network connection. proper process sending encrypted data cipheroutputstream?

the way interpret code cipher initialized encrypt 1 message rsaes-pkcs1-v1_5, because according http://docs.oracle.com/javase/7/docs/technotes/guides/security/standardnames.html#cipher "rsa" refers "the rsa encryption algorithm defined in pkcs #1" guess refers oldest implementation padding scheme , should rsaes-pkcs1-v1_5. if correct, there no way stream produce partial results before whole message (the whole stream) read. should not able send long messages cipher (with 2048 bit rsa key should less 256 bytes).

i assume trying accomplish create secure connection between 2 endpoints? if should not bother low level cryptography , create tls connection. though not trivial set still more easier build secure encrypted communication channel scratch.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -