Serialize MD5 computation-state and resume later?

五迷三道 提交于 2019-12-01 16:35:14
Ryan

HASH objects are not serializable: How to serialize hash objects in Python

Assuming you can pass around the unhashed data:

from Crypto.Hash import MD5

# generate hash
m = MD5.new()
s = "foo"
m.update(s)

# serialize m
serialized = s

# deserialize and continue hash generation
m2 = MD5.new(serialized)
if m2.hexdigest() == m.hexdigest():
    print "success"
m2.update("bar")

I asked Mr Guido V Rossum. He replied that "I don't think there's a way. However it might make a decent feature request. You could submit one to bugs.python.org." So I did.

http://bugs.python.org/issue16059

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!