Instructions for using Python and Hashlib modules:
used for encryption related operations, in the 3.x instead of the MD5 module and SHA module, mainly provide SHA1, SHA224, SHA256, SHA384, SHA512, MD5 algorithm; that is, in the 3.x version, only HASHL The IB module is not present in the MD5 module and the SHA module .
One, the module uses the instruction:
1, hashlib
ImportHASHLIBM=hashlib.md5 () #md5的方法使用m. Update (b"Hello")Print(M.hexdigest ()) m.update (b"My name is xkj")Print(M.hexdigest ()) M2=hashlib.md5 () m2.update (b"Hello my name is xkj")Print(M2.hexdigest ())#hexadecimalPrint(M2.digest ())# BinaryHash=hashlib.sha1 ()#SHA1 method uses hash.update (b"Admin")Print(Hash.hexdigest ()) hash=hashlib.sha256 ()#sha256 method uses hash.update (b"Admin")Print(Hash.hexdigest ()) hash=hashlib.sha512 ()#sha512 method uses hash.update (b"Admin")Print(Hash.hexdigest ())
2. Usage instructions for HMAC templates
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# is used for message authentication instead of password h=hmac.new (' add up '. Encode (" utf-8"),' steady '. Encode ("utf-8 " ) print("HMAC:", H.hexdigest ())
3. function Extension Data
Read more about md5,sha1,sha256 and other introductory articles here https://www.tbs-certificates.co.uk/FAQ/en/sha256.html
Python and encryption