开发者

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

开发者 https://www.devze.com 2023-01-17 09:14 出处:网络
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.

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 cor开发者_开发知识库rect?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消