用 Python 生成的 md5 为什么跟 shell 生成的不一样?

python 代码:

import hashlib
h = hashlib.md5('helloworld')
print h.hexdigest()
---
输出:fc5e038d38a57032085441e7fe7010b0

shell 代码:

$> echo helloworld | md5
---
输出:d73b04b0e696b0945283defa3eee4538
阅读 7.4k
1 个回答

echo默认会在字符串后面加上"\n",可以用-n选项,如下:

➜  ~  echo -n helloworld | md5
fc5e038d38a57032085441e7fe7010b0
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题