title: Difference between HMACSHA256 and HMACSHA512
body: <p>We are using the below code to generate a HMac hash against a sensitive value in C#</p>
  
  <pre><code>public string GenerateHMac(string key, string message)
  {
      var decodedKey = Convert.FromBase64String(key);
  
      var hasher = new HMACSHA256(decodedKey);
  
      var messageBytes = Encoding.Default.GetBytes(message);
  
      var hash = hasher.ComputeHash(messageBytes);
  
      return Convert.ToBase64String(hash);
  }
  </code></pre>
  
  <p>The key passed in is a 256 bit base 64 encoded string.  A question was raised as to whether we should be using HMACSHA256, HMACSHA384 or HMACSHA512 to hash the value.</p>
  
  <ul>
  <li>What are the advantages to using HMACSHA512 over HMACSHA256?</li>
  <li>Is it significantly more secure?</li>
  <li>Are there dramatic performance implications when using a longer key?</li>
  </ul>
  
  <p>As a side note; does the <code>decodedKey</code> value I am passing into the constructor need to be a 512 bit key if I use HMACSHA512?</p>