0

With the same byte array, the result of performing a checksum using .NET Core 3.0's SHA512Managed class is different than the result of using the built-in shasum app in MacOS.

I've triple-checked the byte array is unmodified/identical by iterating over every byte position using File.ReadAllBytes().

Process in code:

var stream = asm.GetManifestResourceStream(resourceName);
var data = new byte[stream.Length];
stream.Read(data, 0, (int)stream.Length);
var sha = new SHA512Managed();
var checksum = sha.ComputeHash(data);

At the command line:

shasum -a512 ./myfile.dat

I'm receiving a good (expected) checksum value from the shasum utility, the iHex app from the AppStore, and the website "passwordsgenerator.net/sha512-hash-generator/".

I'm receiving a bad value from the .NET code above and from the a different website "online-convert.com". Both of which produce the identical bad result!

Is there more than one implementation of the SHA512 algorithm? Since I'm comparing byte arrays, there should be no nonsense involving character encoding, right? Is there something about compiling or reading back an embedded resource in MacOS I should know about?

Any tips or pointers would be greatly appreciated!

David Montgomery
  • 1,618
  • 15
  • 28
  • that would be great to have a repro in your question. Please provide file that produces different hashses? Did you ensure that file is not transformed when saved to the resources, how do you do that btw? Can you extract resource from the manifest and use the tool that produce 'expected' checksum to generate its hash and compare it to the hash of the file that you are packing? – fenixil Sep 25 '19 at 03:19
  • A) Is the stream.Read finishing? You're ignoring the return value, it might not have filled your array. B) Is there a possibility you're encountering some sort of `\n` vs `\r\n` normalization? – bartonjs Sep 26 '19 at 23:44

0 Answers0