Mathematica always interprets the input of the Hash function as a string. I would expect this:
IntegerString[
Hash[FromDigits["00010966776006953D5567439E5E39F86A0D273BEE", 16],
"SHA256"], 16, 64]
to give me:
"445c7a8007a93d8733188288bb320a8fe2debd2ae1b47f0f50bc10bae845c094"
as verified here: Online Hash Calculator
But instead, I get:
"c168f056a6d0238c0df71da640a0892db3f4f2dcac2477810ce7839c55dcf4a0"
I tried to solve the problem by converting the number to an array of bytes and then to a string from these bytes:
IntegerString[
Hash[FromCharacterCode@
IntegerDigits[
FromDigits["00010966776006953D5567439E5E39F86A0D273BEE", 16],
256], "SHA256"], 16, 64]
This works in some cases, but in this particular example, it gives me:
"2d001285e2fe3db967101c75e17e0fc409d88b811e6e926a2bb3088c9ee309a2"
How can I force Mathematica to calculate the hash using the input as a number, not a string? Thanks.
- As you receive help, try to give it too, by answering questions in your area of expertise.
- Take the tour and check the faqs!
- When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Aug 07 '16 at 15:45BinaryWriteto write the 21 bytes to a file, then runningFileHash– george2079 Aug 07 '16 at 19:19ByteArraymight be wort a look as well. – george2079 Aug 07 '16 at 19:26BinaryWriteandFileHashdo work, butByteArraydoes not work because it adds anotherHeadto the expression. – JungHwan Min Aug 07 '16 at 22:08