Python Module Hashlib (provides a common digest algorithm, such as MD5,SHA1, etc.)

Source: Internet
Author: User
Tags sha1


#-*-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.)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.