Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command line SHA-256 hash different from online tools?

I was looking for a quick way to compute the SHA-256 hash of a password so I could upload some test data into a database that we are using Spring Security to authenticate against.

First I found the linux utility sha256sum and ran it again the password "admin" and got this result:

fc8252c8dc55839967c58b9ad755a59b61b67c13227ddae4bd3f78a38bf394f7

Then I tried an couple online services (for fun):

http://www.xorbin.com/tools/sha256-hash-calculator http://www.fileformat.info/tool/hash.htm?text=admin

and both gave me this very different result:

8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918

Why are they different and which is correct?

like image 807
HDave Avatar asked Sep 22 '10 19:09

HDave


2 Answers

I ran into this problem while doing something similar.

What I was doing was something like echo string | sha256sum, I think.

I'd get a different result when I ran this through the php hash generator. The reason was because of the new line that echo added.

I don't know if you're using echo but if you are try echo -n string | sha256num.

like image 200
PaddyDwyer Avatar answered Nov 18 '22 17:11

PaddyDwyer


According to echo -n "admin" | shasum -a 256 on my Mac OS X, the later is correct. Note that you need to do echo -n, otherwise there's a \n in the string that is hashed as well. Since shasum is a Perl script, you might have it as well. If so, try to use that.

like image 20
DarkDust Avatar answered Nov 18 '22 17:11

DarkDust