I'm want to use a REST API which requires a signature, which is a hash of the message using a secret key. I have a JavaScript implementation of it which works, but when I try to do the same thing in C#, it produces a different result which, according to the API response, does not seem to be correct.
The JavaScript code that produces the desired signature:
let signature = crypto.createHmac('sha256', secret_key).update(message).digest('hex');
The C# code that does not produce the same desired signature:
var hash = new HMACSHA256(key);
byte[] signature = hash.ComputeHash(message);
StringBuilder hexDigest = new StringBuilder();
foreach (byte b in signature)
hexDigest.Append(String.Format("{0:x2}", b).ToUpper());
Would appreciate if someone can tell me what I need to change in the C# code to reproduce the same result.