Byte arrays do not match between c # and in nodejs

3

The problem is this, I have this portion of code in C # that generates a token.

SHA256Managed hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(Encoding.ASCII.GetBytes("araña"));
string StringByte = BitConverter.ToString(hash);
Console.WriteLine("bytes :" + StringByte);

//writeline = f686964edf1e0feea8a50cd1352efa94196d6f19bd22ff7abad706ff15852d2e

while in nodejs I try it in the following way

var hash = crypto.createHash('sha256').update('araña','ASCII').digest('hex')

//hash = 2b0231711496dae7e431deb1cc05b714ce1faabc9e742a1c7eb479ccd76ed6df

I can not make them coincide and it should be noted that the error is only when the keyword has a 'Ñ', my code is the node code and the code of C # can not be modified, thank you in advance for your help

    
asked by Arturo Blancarte 30.10.2018 в 19:33
source

1 answer

0

Doing tests I found that c # converts all the special characters in the character '?' (ASCII 63). Maybe the only possible solution is to replace them when converting the string into bytes in the node, being that you can not touch the code in c # and really the ASCII character set comprises less elements than the UTF8

    
answered by 31.10.2018 / 19:04
source