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