28 November 2008

python and md5 hashes - very easy

Using python2.5 and md5 hash is indeed very easy


>>> import hashlib
>>> m = hashlib.md5()
>>> m.update("Nobody inspects")
>>> dir(m)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'block_size', 'copy', 'digest', 'digest_size', 'digestsize', 'hexdigest', 'name', 'update']
>>> m.hexdigest()
'3ef729ccf0cc56079ca546d58083dc12'
>>> len(m.hexdigest())
32


Links:
http://www.python.org/doc/2.5.2/lib/module-hashlib.html