Serialize MD5 computation-state and resume later?

前端 未结 2 1112
感情败类
感情败类 2021-01-17 17:31

I want to serialize/deserialize md5 context. But I don\'t know how to do it in Python. Pseudocode of what I want to do.

import md5
# Start hash generation
m          


        
相关标签:
2条回答
  • 2021-01-17 17:53

    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")
    
    0 讨论(0)
  • 2021-01-17 17:56

    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

    0 讨论(0)
提交回复
热议问题