Probably this is very naive question, based on lack of understanding but I was watching a video from Andreas M. Antonopoulos about blockchain, bitcoin and consensus algorithms and he asked for the SHA-256 output of the string Hello!
. A guy told him the first few characters, and being Windows/C# dev I decided just for fun to check the answer implementing this very simple C# method:
public byte[] Generate(string valueToHash)
{
byte[] hashValue;
byte[] stringToBytes = Encoding.ASCII.GetBytes(valueToHash);
using (SHA256 hashGenerator = SHA256.Create())
{
hashValue = hashGenerator.ComputeHash(stringToBytes);
}
return hashValue;
}
and then output the result using this method:
public static void PrintByteArray(byte[] array)
{
for (int i = 0; i < array.Length; i++)
{
Console.Write($"{array[i]:X2}");
if ((i % 4) == 3) Console.Write(" ");
}
Console.WriteLine();
}
But I got a different result.
I remember in the past that there were sites which were storing a huge databases of hashes and the actual value to produce them and back then it was possible to paste the hash value and if it's something common you will get the actual string. This got me to think that no matter what language/Os you are using, a value hashed with SHA-256 for example would produce the same result. However it seems that this is not entirely the case. The guy from the video who provided the answer turned out (from the comments) to use a Mac machine, so what exactly is causing the SHA-256 to produce different outputs for the same input? Is it the OS, is it the programming language? Maybe I've made mistake in my simple code?
\0
byte or a trailing newline sequence). – SEJPM Jul 31 '19 at 11:17