I have a script in PHP which generates a signed string for an API, and I need to convert it to C#. The output is not matching somehow though, and so the API is returning a 401. What am I missing?
signature = hash_hmac('sha256', 'GET' . _url . hash('sha256', "") . timestamp . nonce, $secret_key);
var signature = SignWithHMAC("GET" + _url + CreateHash("") + timestamp + nonce, secret_key);
public static string SignWithHMAC(byte dataToSign, byte keyBody)
var enc = Encoding.ASCII;
HMACSHA256 hmac = new HMACSHA256(keyBody);
byte buffer = dataToSign;
return Convert.ToBase64String(hmac.ComputeHash(buffer)).Replace("-", "");
public static byte CreateHash(byte data)
SHA256 shaM = new SHA256Managed();
byte result = shaM.ComputeHash(data);
Is there any reason the two different hashing and hmac methods would return different results?