生成从Linux命令行
我知道字符串 “foobar的” 一个SHA256生成使用 http://hash.online-convert.com/sha256-generator生成从Linux命令行
然而命令行壳的SHA 256散列c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
:
[email protected] ~$ echo foobar | sha256sum
aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f -
生成一个不同的散列。我错过了什么?
echo
通常会输出换行符,该换行符被-n
抑制。试试这个:
echo -n foobar | sha256sum
这个命令'sha256sum'与Solaris中的digest命令相同吗? – user3153014 2014-05-09 07:22:24
似乎是这样,http://www.opensolarisforum.org/man/man1/digest.html,'digest -a sha256'应该这样做。 – mvds 2014-05-09 07:46:24
注意:在OS X(BSD)上,它是'echo -n foobar | shasum -a 256' – Olie 2014-10-16 15:26:31
我认为echo
输出一个尾随换行符。尝试使用-n
作为参数来回显以跳过换行符。
echo会生成一个尾随的换行符,它也会被哈希。尝试:
/bin/echo -n foobar | sha256sum
如果命令sha256sum不可用(对小牛为例),你可以使用:
echo -n "foobar" | shasum -a 256
不错!我已经将这添加到我的.bash_profile 函数sha256(){echo -n“$ *”| shasum -a 256} 并且调用方式如下:〜$ sha256 foobar – rbento 2017-02-15 05:52:56
与接受的答案不同,这适用于MacOS – weefwefwqg3 2017-09-17 04:18:46
如果您已经安装openssl
,你可以使用:
echo -n "foobar" | openssl dgst -sha256
对于其他您可以用-md4
,-md5
,-ripemd160
,-sha
,-sha1
,替换,-sha384
,-sha512
或-whirlpool
。
有没有方法可以指定sha512中需要的回合数?我看了一下,找不到它,并想知道你是否会知道? – f1lt3r 2017-06-08 23:57:14
@AlistairMacDonald - 我不知道你在找什么。AFAIK,SHA512需要80轮;如果你想操纵这个功能,它将不再是sha512。顺便说一句,你可以在[crypto.stackexchange.com](https://crypto.stackexchange.com/“Cryptography Stack Exchange”)中搜索/询问你的问题。 – Farahmand 2017-06-09 12:27:30
与接受的答案不同,这适用于MacOS。 – weefwefwqg3 2017-09-17 04:18:22
'sha256sum
koppor
2016-12-17 20:10:29
@koppor'
mvds
2017-02-16 15:07:49