5
I’ve found a flaw or I can’t deal with hashes. I have two bytes arrays random, one generated by an algorithm and one original. I am trying to make the algorithm EXACTLY the same as the original. Visually I managed, with the same bytes, the same size in the same positions.
But when checking the hashes using SHA-256, gives difference between the hashes to the byte arrays identical.
A
is the hash of the original byte-array
A¹
is the hash of the generated byte-array
Ax
are the bytes contained in the original byte-array
Ay
are the bytes contained in the byte-array generated by the algorithm
Note that, Ax
and Ay
are practically identical. But their hashes are different. What is happening?
Method used to calculate hashes:
public static string ToHex(byte[] bytes, bool upperCase) {
using (var k = new HMACSHA256()) {
bytes = k.ComputeHash(bytes);
}
StringBuilder result = new StringBuilder(bytes.Length * 2);
for (int i = 0; i < bytes.Length; i++)
result.Append(bytes[i].ToString(upperCase ? "X2" : "x2"));
return result.ToString();
}
I am currently using the . NET Standard 2.0.
Obs: This also happens with other hashes like MD5.
– CypherPotato