Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an md5 object in python with an initial value [duplicate]

Tags:

python

md5

I have some code that needs to hash certain data, then later on, in another process, continue the hash with more data.

Is there a way to create an object, either from the md5 or hashlib modules, which has a different initial value than 'd41d8cd98f00b204e9800998ecf8427e'? What I mean is something similar to:

x = md5.from_digest('0123456789abcdef')
x.update(new_data)

Note: the less desirable approach would be to save the original md5 object and restore it later, but afaik HASH objects are non-pickleable.

like image 225
itai Avatar asked Dec 31 '13 12:12

itai


People also ask

How do I md5 a file in python?

Correct Way to create MD5 Hash of a file in Python The process of creating an MD5 hash in python is very simple. First import hashlib, then encode your string that you want to hash i.e., converts the string into the byte equivalent using encode(), then pass it through the hashlib. md5() function.

What is the md5 function in python?

As a python programmer, we need hash functions to check the duplicity of data or files, to check data integrity when you transmit data over a public network, storing the password in a database etc. MD5 - MD5 or message digest algorithm will produce a 128-bit hash value.


1 Answers

They(@jon-clements, @itai, @delnan) are right. Until now , you can't , unless you implement one. There are some examples : http://equi4.com/md5/pymd5.py http://rosettacode.org/wiki/MD5/Implementation

like image 176
JJP Avatar answered Oct 28 '22 07:10

JJP