#-*-coding: utf-8-*-
#python 27
#xiaodeng
#python 之 modulehashlib (provides common digest algorithms, such as MD5, SHA1, etc.)
#http: //www.cnblogs.com/BeginMan/p/3328172.html
#Taking the common digest algorithm MD5 as an example, calculate the MD5 value of a string
import hashlib
m = hashlib.md5 () #Create a hash object
m.update (‘xiaodeng’) #Update hash object with string parameters
print m.hexdigest () # accd5818a8547b13180044139260c80d
#The amount of data is very large, you can call update () multiple times in blocks,
#The final calculated result is the same
import hashlib
m = hashlib.md5 ()
m.update (‘xiao’)
m.update (‘deng’)
print m.hexdigest () #Returns a string of hexadecimal digits, accd5818a8547b13180044139260c80d
#print m.digest () #Return the digest as a binary data string value
print m.digest_size #byte size of the generated hash
print m.block_size
#application:
import datetime
key_value = ‘xiaodeng’
now = datetime.datetime.now ()
m = hashlib.md5 ()
string = ‘% s% s’% (key_value, now.strftime (‘% Y% m% d’)) # How to write the encryption method can be determined by the programmer himself, and no one can know
m.update (string)
value = m.hexdigest ()
print value # bff15a80fddc90267a9286806231d7da
Python Module Hashlib (provides a common digest algorithm, such as MD5,SHA1, etc.)