简体   繁体   English

Python hashlib Checksum与linux md5sum不同

[英]Python hashlib Checksum is different from linux md5sum

I am trying to calculate the checksum of the string "test" using the python's hashlib module. 我试图使用python的hashlib模块计算字符串“test”的校验和。 I am using python3. 我正在使用python3。

In [31]: hobj = hashlib.new('md5')
In [32]: hobj.update('test'.encode("UTF-8"))
In [33]: hobj.hexdigest()
Out[33]: '098f6bcd4621d373cade4e832627b4f6'

But when i am trying the same with the linux md5sum the checksum is totally different from the hashlib's output. 但是当我尝试使用linux md5sum时,校验和与hashlib的输出完全不同。

$ echo 'test' | md5sum 
d8e8fca2dc0f896fd7cb4cb0031ba249  -

Is there anything wrong with my python code? 我的python代码有什么问题吗?

Use echo -n 'test' instead. 请改用echo -n 'test' echo will output a newline character ("test\\n") otherwise. echo将输出换行符(“test \\ n”)否则。

$ echo -n 'test' | md5sum 
098f6bcd4621d373cade4e832627b4f6  -

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM