Hashlib Module
For cryptographic related operations, the 3.x replaces the MD5 module and the SHA module, mainly providing SHA1, SHA224, SHA256, SHA384, SHA512, MD5 algorithm
ImportHASHLIBM=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.digest ())#2 binary format hashPrint(Len (M.hexdigest ()))#16 binary format hash" "def digest (self, *args, **kwargs): # Real signature Unknown "" "Return the Digest value as a string of binary data. "" "Pass Def hexdigest (self, *args, **kwargs): # Real signature Unknown" "" Return the Digest value as a string of hexadecimal digits. "" "Pass" "######### MD5 ########Hash=hashlib.md5 () hash.update ('Admin')Print(Hash.hexdigest ())######### SHA1 ########hash =hashlib.sha1 () hash.update ('Admin')Print(Hash.hexdigest ())######### sha256 ########Hash=hashlib.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 ())
Python also has an HMAC module that internally creates keys and content for us to process and then encrypt
Hash message authentication code, or HMAC, is an authentication mechanism based on the message identification Code (authentication code) of Mac. When using HMAC, both sides of the message communication authenticate the authenticity of the message by verifying the authentication key K added in the message;
Generally used in network communication message encryption, the premise is that both parties must first agree on a good key, like a connector password, and then send the message with key to encrypt the message, the receiver with key + message plaintext again encrypted, take the encrypted value with the sender's relative ratio is equal, so that the authenticity of the message can be verified, And the legitimacy of the sender.
Import= hmac.new (b'hello', b'cabel') Print(H.hexdigest ())
Python's Hashlib module