title: c# vs java HMACSHA1
body: <p>I'm trying to implement this Java SHA1 in C#. Not sure why my results in C# are different.</p>
  
  <p>I'm hesitant to post the key and data which create the hash, though filling in any value should produce differing results in each implementation.</p>
  
  <p>Java:</p>
  
  <pre><code>String key = "key";
  String data = "data";
  String algorithm = "HmacSHA1";
  Charset charset = Charset.forName("utf-8");
  SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), algorithm);
  Mac mac = Mac.getInstance(algorithm);
  mac.init(signingKey);
  return new String(Base64.encodeBase64(mac.doFinal(data.getBytes(charset))), charset);
  </code></pre>
  
  <p>produces: g1SZb73Vg6bV7VhFQ2KkCLy98rE=</p>
  
  <p>C#:</p>
  
  <pre><code>String key = "key";
  String data = "data";
  byte[] aKey = UTF8Encoding.UTF8.GetBytes(key);
  byte[] aData = UTF8Encoding.UTF8.GetBytes(data);
  HMACSHA1 oEncode = new HMACSHA1(aKey);
  byte[] aBytes = oEncode.ComputeHash(aData);
  return Convert.ToBase64String(aBytes);
  </code></pre>
  
  <p>produces: 50Hg/Hsq4v+iYrXJYpxxHE5q3RU=</p>