python - md5sum 输出和 Python hashlib 输出有什么区别?

标签 python bash md5 gravatar

为什么 hashlib.md5().hexdigest() 的输出与 md5sumopenssl 的输出不同?

$ 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 输出有效,但 md5sumopenssl 输出无效。

最佳答案

echo 默认添加隐式换行符。

$ echo -n "test string" | openssl dgst -md5
(stdin)= 6f8db599de986fab7a21625b7916589c

关于python - md5sum 输出和 Python hashlib 输出有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50533188/

相关文章:

python - pipenv 仅在主目录中安装 .venv

linux - bash 中退格键不会删除 tput 命令的下划线

bash - sshing时传递bash变量

md5 - 是否有将摘要放入正在摘要的文件中的算法?

java - 循环 MD5 计算时缓慢且内存泄漏

python - 将一个简单的字典导出到 python 中的 Excel 文件中

python - 如何测试django中的编辑功能? (错误 django.db.utils.IntegrityError : NOT NULL constraint failed)

python - 如何在给定相对 bbox 坐标的情况下在此图片上裁剪车号?

string - Bash:无法将字符串附加到现有字符串 - 它似乎覆盖了该字符串的开头

java - 安卓 : How to create HMAC MD5 string?