Python hashlib module

Source: Internet
Author: User

The Hashlib module is used to encrypt related operations, replacing the MD5 module and the SHA module in 3.x, mainly providing SHA1, SHA224, SHA256, SHA384, SHA512, MD5 algorithm import hashlib m = Hashlib.md5 () m . Update (b "Hello") M.update (b "It ' s Me") print (M.digest ()) m.update (b "It's been a long time since last time we ...") Print (M.D    Igest ()) #2进制格式hashprint (Len (M.hexdigest ())) #16进制格式hash "Def Digest (self, *args, **kwargs): # Real Signature Unknown    "" "Return the Digest value as a string of binary data." " Passdef hexdigest (self, *args, **kwargs): # Real signature Unknown "" "Return the Digest value as a string of HEXADECIM Al digits. "" "Pass" "Import Hashlib # ######## MD5 ######## hash = HASHLIB.MD5 () hash.update (' admin ') print (Hash.hexdigest ()) # # # # ##### SHA1 ######## hash = HASHLIB.SHA1 () hash.update (' admin ') print (Hash.hexdigest ()) # ######## sha256 ######## hash = has hlib.sha256 () hash.update (' admin ') print (Hash.hexdigest ()) # ######## sha384 ######## hash = hashlib.sha384 () Hash.update (' admin ') print (Hash.hexdigest ()) # ######## sha512 ######## hash = HASHLIB.Sha512 () hash.update (' admin ') print (Hash.hexdigest ()) Not enough to hang? Python also has an HMAC module that internally creates a key and content for us to process and then encrypt the hash message authentication code, or HMAC, which is an authentication mechanism based on the message Identification code MAC (msg authentication code). When using HMAC, both sides of the message communication can authenticate the authenticity of the message by verifying the authentication key K which is added in the message. Generally used in network communication message encryption, the premise is that both parties must first agree a good key, like a connector password, and then send the message to use key to encrypt messages, the receiver with key + message plaintext again encrypted, The relative ratio of the encrypted value to the sender is equal, which verifies the authenticity of the message and the legitimacy of the sender. Import Hmach = hmac.new (b ' King cover to the Tiger ', B ' Pagoda Town River Demon ') print h.hexdigest () more about md5,sha1,sha256 and other introductory articles see here https://  Www.tbs-certificates.co.uk/FAQ/en/sha256.html

Python hashlib module

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.