Encryption with tcpclient and tcplistner?
-
Hi! im new to encryption and would appreciatelittle help :) currently im using CryptoStream(RijandelManaged) with NetworkStream and it seems to work except that i dont get all the data right away. this is my current code:
RijndaelManaged r = new RijndaelManaged();
cryptoReadStream = new CryptoStream(netStream, r.CreateDecryptor(key, iv), CryptoStreamMode.Read);byte[] buffer= new byte[10000];
cryptoReadStream.Read(buffer,0, buffer.Length);the problem is: 1.cryptoStream.Read blocks until 10000 bytes have been recived, unlike NetworkStream.Read which returns when theres is nothing more to read, this is a problem beacuse if the server only writes 10 bytes then ill have to wait forever before i can diplay the results.
-
Hi! im new to encryption and would appreciatelittle help :) currently im using CryptoStream(RijandelManaged) with NetworkStream and it seems to work except that i dont get all the data right away. this is my current code:
RijndaelManaged r = new RijndaelManaged();
cryptoReadStream = new CryptoStream(netStream, r.CreateDecryptor(key, iv), CryptoStreamMode.Read);byte[] buffer= new byte[10000];
cryptoReadStream.Read(buffer,0, buffer.Length);the problem is: 1.cryptoStream.Read blocks until 10000 bytes have been recived, unlike NetworkStream.Read which returns when theres is nothing more to read, this is a problem beacuse if the server only writes 10 bytes then ill have to wait forever before i can diplay the results.
You can read it to an intermediate MemoryStream, still cryptografed, and after finishing reading you use the cryptoStream to decrypt the data.
Regards, Leonardo Muzzi