英文:
Why does Go sha256 give different result than Ubuntu command sha256sum?
问题
Golang playground中给出的链接中的代码使用Go的sha256库生成的结果与在Ubuntu Linux中运行以下命令得到的结果不同。
echo "sha1 this string" | sha256sum
Go的结果:fceab3bb749b11a43b89f21ccd28e3f5d8b38d5b23eeea960fc169ab482ee2cd
Linux的结果:62d44fd0392ed998179bfd4a162141d7000d1f9aa4fae26465e2e4f57d3a420e
这是否不是在Go中创建摘要的正确方法?有人可以解释一下这里发生了什么吗?
英文:
Golang playground link given in a SO question uses the sha256 lib of Go gives a different result than running the following command in Ubuntu linux.
echo "sha1 this string" | sha256sum
Go's result: fceab3bb749b11a43b89f21ccd28e3f5d8b38d5b23eeea960fc169ab482ee2cd
Linux result: 62d44fd0392ed998179bfd4a162141d7000d1f9aa4fae26465e2e4f57d3a420e
Is this not the correct way to create a digest in Go? Can someone explain what is going on here?
答案1
得分: 13
因为echo命令会附加一个\n
字符。尝试使用echo -n
命令:
echo -n "sha1 this string" | gsha256sum
fceab3bb749b11a43b89f21ccd28e3f5d8b38d5b23eeea960fc169ab482ee2cd -
英文:
Because echo appends a \n
character. Try doing echo -n
:
echo -n "sha1 this string" | gsha256sum
fceab3bb749b11a43b89f21ccd28e3f5d8b38d5b23eeea960fc169ab482ee2cd -
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论