2

我正在尝试复制此处找到的值http://www.nsrl.nist.gov/testdata/

SHA-256 应该将“abc”散列到

 BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD

但是在带有sha256 sum的linux下我得到了这个。

edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb

adam@adam-desktop:~/code/android-casual/trunk/CASUALcore$ echo "abc">./test.tmp
adam@adam-desktop:~/code/android-casual/trunk/CASUALcore$ sha256sum test.tmp
edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb  test.tmp
adam@adam-desktop:~/code/android-casual/trunk/CASUALcore$ echo "abc"|sha256sum
edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb  -
4

1 回答 1

4

那是因为echo在字符串中附加了一个换行符。改用echo -n

$ echo "abc" | shasum -a 256
edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb  -
$ echo -n "abc" | shasum -a 256
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad  -
于 2013-07-26T15:44:23.813 回答