c# - Why is this HMAC SHA256 hash I'm creating using the wrong character encoding? -


i'm doing in c# create hash:

        using (var hmacsha256 = new hmacsha256(encoding.ascii.getbytes(secret)))         {             return system.text.encoding.utf8.getstring(hmacsha256.computehash(encoding.ascii.getbytes(message)));         } 

i use following json:

{     "client_id": "26075235",     "client_version": "1.0.0",     "event": "app.uninstall",     "timestamp": "1478741247",     "data": {         "user_id": "62581379",         "site_id": "837771289247593785",         "domain": ""     } } 

and this:

sx�m�.-�n�0�v@�i!s��iec,�56

i'm expecting hash this:

960aff6c335a87e6077f41066358980a88db54062505875e5a8c363ded9d027e

if hashing this:

        using (var hmacsha256 = new hmacsha256(encoding.utf8.getbytes(secret)))         {             return system.text.encoding.utf8.getstring(hmacsha256.computehash(encoding.utf8.getbytes(message)));         } 

i same thing. how return i'm expecting?

what not understanding this?

an arbitrary binary data can not converted string... seems want bitconverter.tostring , convert.tobase64string or system.runtime.remoting.metadata.w3cxsd2001.soapbase64binary, instead of system.text.encoding.utf8.getstring


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -