Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我echo lol | md5在 Mac Terminal 中运行,它返回: 59bcc3ad6775562f845953cf01624225
echo lol | md5
59bcc3ad6775562f845953cf01624225
但后来我print hashlib.md5("lol").hexdigest()在 python 2.7 中运行,我得到: 9cdfb439c7876e703e307864c9167a15
print hashlib.md5("lol").hexdigest()
9cdfb439c7876e703e307864c9167a15
我究竟做错了什么?
echo默认情况下在末尾附加一个换行符,因此它会给出不同的哈希值。
echo
在 python 中,以换行符结尾
>>> print hashlib.md5("lol\n").hexdigest() 59bcc3ad6775562f845953cf01624225
标准 echo 命令,省略换行符结尾。
$ echo -n lol | md5sum - 9cdfb439c7876e703e307864c9167a15 -