This module is derived from MD5C.C
by RSA Data Security, Inc.
To use it, include from pymd5 import *
in your Python 3 script.
md5(string='', state=None, count=0)
Returns a new md5
objects and processes string. Optional advanced parameters allow you to resume an earlier computation by setting the internal state of the function and the counter of message bits processed so far. Most of the interface matches Python's standard hashlib
.
>>> m = md5()
md5.update(arg)
Updates the md5
object with the string arg
. Repeated calls are equivalent to a single call with the concatenation of all the arguments.
>>> m.update("msg")
md5.digest()
Returns the digest of the strings passed to the update()
method so far. This may contain non-ASCII characters, including NULL
bytes.
>>> print(m.digest())
b'\xf2\xbc[\x1d\x86\x98p\xd7h\x8fq\xb2\xd8p0\xbd'
md5.hexdigest()
Like digest()
but returns a string of double length, containing only hexadecimal digits.
>>> print(m.hexdigest())
f2bc5b1d869870d7688f71b2d87030bd
md5.digest_size
Returns the size of the resulting hash in bytes.
>>> print(m.digest_size)
16
md5.block_size
Returns the internal block size of the hash algorithm in bytes.
>>> print(m.block_size)
64
padding(msg_bits)
Given a message size (in bits), returns the full padding byte string that should be appended to the end of a message to reach a multiple of the block size.
>>> p = pymd5.padding(8) # 8 bits (1 byte)
>>> print(len(p))
63
>>> p = pymd5.padding(16) # 16 bits (2 bytes)
>>> print(len(p))
62