小编VAG*_*rus的帖子

比较python中两个文件的md5哈希值

我想比较两个文件的哈希值。但是不管文件是否不同,即使哈希比较结果不同

这是代码:

import hashlib

hasher1 = hashlib.md5()
afile1 = open('canvas.png', 'rb')
buf1 = afile1.read()
a = hasher1.update(buf1)
print(str(hasher1.hexdigest()))

hasher2 = hashlib.md5()
afile2 = open('img5.png', 'rb')
buf2 = afile2.read()
b = hasher2.update(buf2)
print(str(hasher2.hexdigest()))

print(str(a) == str(b))
Run Code Online (Sandbox Code Playgroud)

输出:

614c9853a7f62c5b60d7d15bde80708f
76dc116b2c1b19b265db5e657846e649
True

Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)

python hash md5 hashlib python-3.x

3
推荐指数
1
解决办法
5837
查看次数

标签 统计

hash ×1

hashlib ×1

md5 ×1

python ×1

python-3.x ×1