title: How to efficiently generate strong ETags using a System.Net.Cryptography HashAlgorithm?
body: <p>When handling HttpRequestMessages in WebAPI2, we're looking at multiple ways to handle If-None-Match using strong ETags.</p>
  
  <p>Hashing the response content to a strong ETag is the most obvious solution but needs the hashing process to scale.</p>
  
  <p>It appears that the best practice code for generating a hash is something like:</p>
  
  <pre><code>using (var hasher = SHA1.Create())
      return hasher.ComputeHash(stream);
  </code></pre>
  
  <p>What costs are associated with creating a HashAlgorithm object?</p>
  
  <p>Is using a byte array any more efficient than a stream?</p>
  
  <pre><code>using (var hasher = SHA1.Create())
      return hasher.ComputeHash(byteArray);
  </code></pre>
  
  <p>I've encountered some info suggesting that the managed version of some algorithms might be stateless, possibly allowing ComputeHash to be called multiple times on the same object, but that makes me wonder if that also means there is no real cost associated with creating a new object each time.</p>
  
  <p>Thanks in advance!</p>