openstack@openstack:~$ echo "abc" | shasum
03cfd743661f07975fa2f1220c5194cbaff48451 -
而使用Java实现SHA1输出:
a9993e364706816aba3e25717850c26c9cd0d89d
相同算法, 居然结果不同, 蛋疼!
原因:
由于echo输出结果默认换行, 带上-n去除默认换行, 则结果相同^_^!
openstack@openstack:~$ echo -n "abc" | shasum
a9993e364706816aba3e25717850c26c9cd0d89d -
建议printf
openstack@openstack:~$ printf "abc" | shasum
a9993e364706816aba3e25717850c26c9cd0d89d -