The hashlib python module is dedicated to hash algorithm library, which includes md5, sha1, sha224, sha256, sha384, sha512, are summarized
md5 is used as follows:
The MD5
the MD5 is an irreversible encryption algorithm, is currently one of the most robust encryption algorithm, an inverse operation is still not possible to program is developed which corresponds to any string may be secured as a unique piece of code of a fixed length.
First, use:
Import hashlib # from hashlib Import MD5 method: M1 = hashlib.md5 () # configured to hash the object m1.update ( ' the Hello ' ) # To encrypt a string which, to put update in m1.update ( ' , ' ) m1.update ( ' Python ' ) method two: M2 = hashlib.md5 ( ' the Hello, Python ' ) method with the same effect as two methods in two ways Print M1 # <Object @ 0000000003A586E8 the HASH MD5> Print M2 # <MD5 HASH object @ 0000000003A58418>
Two, hash.digest () and hash.hexdigest () the difference:
hash.digest ()
Returns the summary data as a binary string value
hash.hexdigest ()
Returns summary, the data string values as hexadecimal
import hashlib m = hashlib.md5('Hello,python') print m.digest() print m.hexdigest()
Three, hash.digest () and hash.hexdigest () conversion:
print out the result is m1.hexdigest () converted into m1.digest ()
import binascii hexdigest_to_digest = binascii.unhexlify('171712eceb3f8ba8223f0f15d924c070') print hexdigest_to_digest