Linux SHA-256 command line different from online tools?

I was looking for a quick way to calculate the SHA-256 password hash so that I could load some test data into a database in which we use Spring Security for authentication.

First I found the linux sha256sum utility and ran the password β€œadmin” again and got this result:

 fc8252c8dc55839967c58b9ad755a59b61b67c13227ddae4bd3f78a38bf394f7 

Then I tried a couple of 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 a completely different result:

 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 

Why are they different, and what is right?

+4
source share
2 answers

I ran into this problem while doing something similar.

What I did was like an echo string | sha256sum echo string | sha256sum , I think.

I would have got a different result when I ran this through the php hash generator. The reason was that a new line added an echo.

I don't know if you use echo, but if you try echo -n string | sha256num echo -n string | sha256num .

+15
source

According to echo -n "admin" | shasum -a 256 echo -n "admin" | shasum -a 256 on my Mac OS X, a later version is correct. Note that you need to do echo -n , otherwise there \n in the line, which is also hashed. Since shasum is a Perl script, you may have this as well. If so, try using this.

+5
source

All Articles