SHA-256测试向量

时间:2013-07-26 15:37:58

标签: linux testing sha256

我试图复制http://www.nsrl.nist.gov/testdata/

中找到的值

SHA-256应该哈希" abc"

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

但在linux下使用sha256总和,我得到了这个。

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  -

1 个答案:

答案 0 :(得分:2)

那是因为echo在字符串后附加换行符。请改用echo -n

$ echo "abc" | shasum -a 256
edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb  -
$ echo -n "abc" | shasum -a 256
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad  -