title: HMAC SHA 256 decode/encode issues
body: <p>Hey all I am trying to figure out why my HAC-SHA-256 encryption and decryption is not matching up from my Arduino code to my .net code:</p>
  <p>C# code:</p>
  <pre><code>Dim message As String = &quot;Hi There&quot;
  Dim expectedHex As String = &quot;&quot;
  
  TextBox1.Text = (Convert.ToString(&quot;Ref : &quot;) &amp; expectedHex)
  
  'Test out the HMAC hash method
  Dim key As String = &quot;61574d6b157f757d02457573556645750e0341481b127a07476303136c005145436c7b46651c6e4f4f040e1569464a794e534309097258550c17616075060950&quot;
  Dim hashHMACHex__1 As String = HashHMACHex(key, message)
  
  TextBox2.Text = (Convert.ToString(&quot;HMAC: &quot;) &amp; hashHMACHex__1)
  
  ' Test out the SHA hash method
  Dim innerKey As String = &quot;61574d6b157f757d02457573556645750e0341481b127a07476303136c005145436c7b46651c6e4f4f040e1569464a794e534309097258550c17616075060950&quot;
  Dim outerKey As String = &quot;0b3d27017f151f17682f1f193f0c2f1f64692b227178106d2d096979066a3b2f2906112c0f760425256e647f032c2013243929636318323f667d0b0a1f6c633a&quot;
  Dim hashSHAHex__2 As String = HashSHAHex(innerKey, outerKey, message)
  
  TextBox3.Text=(Convert.ToString(&quot;SHA : &quot;) &amp; hashSHAHex__2)
  </code></pre>
  <p>Arduino code:</p>
  <pre><code>char *myData = &quot;61574d6b157f757d02457573556645750e0341481b127a07476303136c005145436c7b46651c6e4f4f040e1569464a794e534309097258550c17616075060950#(128)&quot;;
  
  void printHash(uint8_t* hash) {
    int i;
    for (i=0; i&lt;32; i++) {
      Serial.print(&quot;0123456789abcdef&quot;[hash[i]&gt;&gt;4]);
      Serial.print(&quot;0123456789abcdef&quot;[hash[i]&amp;0xf]);
    }
    Serial.println();
  }
  
  uint8_t* hash;
    uint32_t a;
    unsigned long ms;
    Serial.println(&quot;Test: RFC4231 4.2&quot;);
    Serial.println(&quot;&quot;);
    Serial.print(&quot;Result:&quot;);
    ms = micros();
    Sha256.initHmac((uint8_t *)myData,128);
    Sha256.print(&quot;Hi There&quot;);
    printHash(Sha256.resultHmac());
    Serial.print(&quot; Hash took : &quot;);
    Serial.print((micros() - ms));
    Serial.println(&quot; micros&quot;);
    Serial.println();
  </code></pre>
  <p>The output from the .net program is this:</p>
  <blockquote>
  <p>HMAC: 2d484b68dae3866fbcbf182071c3bf5e86f40ab6c2f3bc72d69fe0d132bf771e</p>
  <p>SHA : 5929bc8b6968e763c7f23090f7d6194c4f1377bd8f6e4b781a5ecdb8e8f91f8f</p>
  </blockquote>
  <p>And the Arduino output:</p>
  <blockquote>
  <p>Result:9a9f6119b41604441db0a75bad6c4e1653a4d00781d4b177e99fe850ad543051</p>
  </blockquote>
  <p>I'm not sure what <strong>innerKey</strong> and <strong>outterKey</strong> is in the .net program. That may be the cause of me not getting the correct values?</p>
  <p><a href="http://forum.arduino.cc/index.php?action=dlattach;topic=464844.0;attach=204997" rel="nofollow noreferrer">Attached</a> is the full code for both the .net program and the arduino sketch.</p>