title: C# equivalent to hash_hmac in PHP
body: <p>using .NET and C# i need to provide an integrity string using HMAC SHA512 to a PHP server .
  Using in C#  :</p>
  
  <pre><code>Encoding encoding = Encoding.UTF8;
  byte[] keyByte = encoding.GetBytes(key);
  HMACSHA512 hmacsha512 = new HMACSHA512(keyByte);
  byte[] messageBytes = encoding.GetBytes(message);
  byte[]  hashmessage = hmacsha512.ComputeHash(messageBytes);
  return(ByteToString(hashmessage).toUpper());
  </code></pre>
  
  <p>But it doesn't match with PHP hash_hmac()
  PHP code :</p>
  
  <pre><code>$hmac = strtoupper(hash_hmac($pbx_hash, $msg, $binKey));
  </code></pre>
  
  <p>I try to change encoding in C# (utf8, ASCII,Unicode) Without success.</p>
  
  <p>I've tried many solution found on the net but nothing give the same string :(</p>
  
  <p>I can't change the PHP code,  and doesn't see what's wrong in C#</p>
  
  <p><strong>Edit</strong> This is <code>ByteToString</code> (copied from the comment):</p>
  
  <pre><code>static string ByteToString(byte[] buff)
  {
      string sbinary = "";
      for (int i = 0; i &lt; buff.Length; i++)
      {
          sbinary += buff[i].ToString("X2"); /* hex format */
      }
      return (sbinary);
  }    
  </code></pre>
  
  <p>After many tets, in found that i get the same results if PHP hash_hmac key is a string, not a byte Array . Seems that the problem is with the PHP convert function $binKey = pack("H*", $keyTest); </p>