TAG: crypto

Software Engineer. Stuff and nonsense. The usually short ramblings of Chris McKee.

How to match HMACSHA256 between C# & Python

Things are rarely simple or obvious when working across languages; especially when one is .net. Rather than waste time here's the code, in its long form. Test parameters With a key 182634d8894831d5dbce3b3185c50881 and a message or data value of some random junk with both solutions we should receive d94ed997943420b7d5dfb9b31ae236b7b5225510d8f0314c54ad44fb5fd44a06 C# public string HmacSHA256(string key, string data) { string hash; ASCIIEncoding encoder = new ASCIIEncoding(); Byte[] code = encoder.GetBytes(key); using (HMACSHA256 hmac = new HMACSHA256(code)) { Byte[] hmBytes…