views:

112

answers:

2

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?

+7  A: 

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.

kertap
+1 for `echo -n`.
Manuel Faux
In the immortal words of Homer Simpson --- DOH!
HDave
+2  A: 

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.

DarkDust