【发布时间】:2018-05-25 16:11:25
【问题描述】:
为什么hashlib.md5().hexdigest() 的输出与md5sum 和openssl 的输出不同?
$ echo "test string" | md5sum
f299060e0383392ebeac64b714eca7e3 -
$ echo "test string" | openssl dgst -md5
(stdin)= f299060e0383392ebeac64b714eca7e3
$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from hashlib import md5
>>> print(md5("test string").hexdigest())
6f8db599de986fab7a21625b7916589c
我在尝试生成用于 Gravatar 的 md5 摘要时注意到了这一点。 Python hashlib 输出有效,但 md5sum 和 openssl 输出无效。
【问题讨论】: