Python module Hashlib (provides multiple different encryption algorithms)

Source: Internet
Author: User
Tags md5 hash sha1

Hashlib is a security hash and message digest that provides several different cryptographic algorithm excuses, such as SHA1, SHA224, SHA256, SHA384, SHA512, MD5, and so on.

ImportHASHLIBM= HASHLIB.MD5 ()#Create a Hash object, MD5: (message-digest algorithm 5) message digest algorithm, to obtain a 128-bit cipherPrintM#<md5 HASH Object @ 000000000254adf0>M.update ('Beginman')#update Hash object with string parameterPrintM.digest ()#returns the digest as a binary data string valuePrintM.hexdigest ()#returns a hexadecimal numeric string 0b28251e684dfbd9102f8b6f0281c0c5PrintM.digest_size# -PrintM.block_size# -

H = hashlib.new ('MD5')PrintH#<md5 HASH Object @ 000000000260bdb0>H2 = Hashlib.new ('ripemd160',' What')PrintH2#<ripemd160 HASH Object @ 000000000271b9f0>H.update ('Beginman')PrintH.hexdigest ()#666fc5baa93a7fb207c5bfff03b67732#equivalents =hashlib.md5 () s.update ('Beginman')PrintS.hexdigest ()#666fc5baa93a7fb207c5bfff03b67732PrintH2.hexdigest ()#9c1185a5c5e9fc54612808977ee8f548b2258d31

# Properties print hashlib.algorithms    #(' MD5 ', ' SHA1 ', ' sha224 ', ' sha256 ', ' sha384 ', ' sha512 ')    List all cryptographic algorithms print h.digest_size         #print h.block_size           #Theinternal block size of the hash algorithm in bytes.

Common methods

Hash.update (ARG)

Update the hash object with a string argument, m.update (a) if the same hash object repeats the method call; M.update (b) is equivalent to m.update (a+b).

Hash.digest ()

Returns a digest, as a binary data string value,

Hash.hexdigest ()

Returns a summary, as a hexadecimal data string value,

Import'/beginman/'== '%s%s  ' % (Key_value,now.strftime ("%y%m%d"=  M.hexdigest ()print#8db42d3e90b41105ed061b8347a7c850

Python module Hashlib (provides multiple different encryption algorithms)

Related Article

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.