title: c# Computing Hashes - Persisting state between multiple streams
body: <p>I'm currently implementing chunked file uploads. Ideally I want to compute a SHA1 hash of the uploaded file. However, I am streaming the file directly to the database which is in a remote location so is a performance hit each time it is accessed. </p>
  
  <p>I am using the following code to compute the hash of a single bulk upload as used in our offline application:</p>
  
  <pre><code>...
  ...
  using (var uploadStream = SqlDataUploadStream.Create(initial, subsequent))
  using (var sha1Hasher = System.Security.Cryptography.SHA1.Create())
  using (var hashStream = new CryptoStream(uploadStream, sha1Hasher, CryptoStreamMode.Write))
  {
      ...
      Copy to hashStream here...
      ...
  }
  </code></pre>
  
  <p>Of course since the uploads via HTTP are being chunked, there isn't a single continuous stream I can compute the hash against.</p>
  
  <p>However, if I can somehow get and set the internal state of the hashing class itself I could persist the state between chunk posts and compute the hash like that without having to go back to the database at the end to read the whole thing again. Unfortunately a quick look at MSDN page for the SHA1 class, nothing jumped out at me that I could use to get the internal state.</p>
  
  <p>I could persist the whole hash class in session, but as it wants to be disposed I am a bit weary of doing this just in case something goes wrong and I don't get a chance to manually dispose it.</p>
  
  <p>So, is there any way I can grab the internal state?</p>