title: A better approach to encrypt and transfer a file
body: <p>To transfer a file over socket I'd first try and generate a <strong>hash</strong> for the original file, then I try to transfer to my mock server and after the server has received the file it will also generate a <strong>hash</strong> and then compare both to see if the file has not been corrupted during the transfer.</p>
  
  <p>Now I am trying to transfer a file I need to encrypt, from my android phone to my mock server, I thought of doing this</p>
  
  <pre><code>while(..reading file from stream){
  //encrypt read bytes
  //write read bytes to socket
  }
  </code></pre>
  
  <p>D problem is I am unsure of how to generate a hash for it that way.
  Or will this be a better approach:</p>
  
  <pre><code>While(reading normal fileA..){
  //encrypt read bytes
  //write d encrypted bytes  in another fileB
  }
  //after done
  //generate a hash from FileB 
  </code></pre>
  
  <p>Then I can send the encrypted file and hash to server and generate a hash and compare</p>
  
  <p>What if  fileA is 1gb in Size, if I choose option 2 I'd need to generate another 1gb of d encrypted fileB and that's consuming space!</p>
  
  <p>Which would b a better approach? Thanks in advance</p>