title: How to use stream cipher to encrypt TCP data?
body: <p>i try to use chacha20 encryption in my network software but i encounter a problem</p>
  
  <p>if i encrypt 4 bytes data: <code>0x01 0x02 0x03 0x04</code> on server</p>
  
  <p>and get the ciphertext: <code>0xd2 0xd3 0xc4 0xd5</code>, then send it to client </p>
  
  <p>the client may receive &lt;= 4bytes at a time</p>
  
  <p>provided that client only recv <code>0xd2 0xd3</code> at first ,</p>
  
  <p>it can decrypt data properly and get plaintext <code>0x01 0x02</code></p>
  
  <p>but when client recv the last 2 bytes <code>0xc4 0xd5</code> </p>
  
  <p>it seems that the data can't be decrypt using the same nonce and key</p>
  
  <p>so is there a way to solve the problem</p>
  
  <p>adding length data as prefix before sending is a solution,but it's weird because i am using stream cipher.</p>