python hashlib和sha512sum工具在SHA512中的区别 [英] Difference in SHA512 between python hashlib and sha512sum tool

查看:328
本文介绍了python hashlib和sha512sum工具在SHA512中的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从linux'sha512sum'工具和python hashlib库中获得了不同的消息摘要.

I am getting different message digests from the linux 'sha512sum' tool and the python hashlib library.

这是我在Ubuntu 8.10上获得的内容:

Here is what I get on my Ubuntu 8.10:

$ echo test | sha512sum
0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123  -

$ python
Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> hashlib.sha512("test").hexdigest()
'ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff'

两者都应计算字符串"test"的消息摘要,为什么您认为我得到不同的结果?

Both should calculate the message digest of the string "test", why do you think I am getting different results?

推荐答案

我认为不同之处在于,echo在其输出中添加了换行符. 尝试echo -n测试| sha512sum

I think the difference is that echo adds a newline character to its output. Try echo -n test | sha512sum

这篇关于python hashlib和sha512sum工具在SHA512中的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆