Is the md5sum linux command working right?

落花浮王杯 提交于 2019-12-08 00:09:00

问题


According to Wikipedia, the md5 sum of an empty string is d41d8cd98f00b204e9800998ecf8427e

I confirmed this with my md5 library

However, when I run

echo "" | md5sum

in my linux shell, I get 68b329da9893e34099c7d8ad5cb9c940 -

In fact, none of my hashes match the output of the md5sum command.

Any thoughts on this discrepancy?


回答1:


With that command, you are calculating the md5sum of a single newline character. Try instead:

echo -n "" | md5sum



回答2:


You must eliminate the new line that echo produces

$ echo -n '' | md5
d41d8cd98f00b204e9800998ecf8427e



回答3:


Try:

echo -n | md5sum

Without the '-n', echo outputs a newline, which md5sum duly processes.




回答4:


use the more portable printf

printf "" | md5sum


来源:https://stackoverflow.com/questions/1604892/is-the-md5sum-linux-command-working-right

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!