简体   繁体   English

Linux命令行SHA-256哈希不同于在线工具?

[英]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. 我正在寻找一种快速计算密码的SHA-256哈希的方法,这样我就可以将一些测试数据上传到我们使用Spring Security进行身份验证的数据库中。

First I found the linux utility sha256sum and ran it again the password "admin" and got this result: 首先,我找到了linux实用程序sha256sum并再次运行了密码“admin”并得到了这个结果:

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 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? 为什么它们不同,哪个是正确的?

I ran into this problem while doing something similar. 在做类似的事情时遇到了这个问题。

What I was doing was something like echo string | sha256sum 我在做什么就像echo string | sha256sum echo string | sha256sum , I think. echo string | sha256sum ,我想。

I'd get a different result when I ran this through the php hash generator. 当我通过php哈希生成器运行时,我会得到不同的结果。 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 我不知道你是否正在使用echo但是如果你正在尝试echo -n string | sha256num echo -n string | sha256num . echo -n string | sha256num

According to echo -n "admin" | shasum -a 256 根据echo -n "admin" | shasum -a 256 echo -n "admin" | shasum -a 256 on my Mac OS X, the later is correct. echo -n "admin" | shasum -a 256在我的Mac OS X上,后者是正确的。 Note that you need to do echo -n , otherwise there's a \\n in the string that is hashed as well. 请注意,您需要执行echo -n ,否则字符串中的\\n也会进行哈希处理。 Since shasum is a Perl script, you might have it as well. 由于shasum是一个Perl脚本,你也可以拥有它。 If so, try to use that. 如果是这样,请尝试使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM