I. Hashlib module
For cryptographic related operations, the 3.x force replaces the MD5 module and the SHA module, providing
: SHA1,SHA224,SHA256,SHA384,SHA512,MD5 algorithm.
1. Use the Hashlib module for MD5 encryption.
Import= hashlib.md5 () m.update (b"Hello") m.update (b " It ' s me " )print(m.hexdigest ()) m.update (b"It ' s been a long time since last Time we ... " )print(M.digest ())
Note: Hashlib.md5 (): Creates a MD5 encryption parameter.
Note: the variable. hexdigest (): Hexadecimal encryption.
Note: Variables. Digest (): Binary encryption
Note: There are a total of 32 values.
2. Encrypt using the SHA1 algorithm.
Import= hashlib.sha1 () s2.update (b"ABC")Print (S2.hexdigest ())
Note: There are a total of 38 values.
3. Encrypting using the SHA256 algorithm
S2 = hashlib.sha256 () s2.update (b"ABC")print( S2.hexdigest ())print(len (S2.hexdigest ()))
Note: There are 64 encrypted values.
4. Encrypt using the SHA384 algorithm.
Import= hashlib.sha384 () s2.update (b"ABC")Print (S2.hexdigest ())print(len (S2.hexdigest ()))
Note: There are 96 encrypted values.
5. Encrypt using the SHA512 algorithm.
Import= hashlib.sha512 () s2.update (b"ABC")Print (S2.hexdigest ())print(len (S2.hexdigest ()))
Note: There are 128 encrypted values.
Two. Advanced Encryption algorithm
Import= hmac.new ('wueiqi') h.update ('Hellowo ' )print h.hexdigest ()
Note: the equivalent of encryption and then a layer of encryption. Double-layer encryption.
Import= hmac.new (b"xsk","y wind x". Encode ( encoding="utf-8")print(h.digest ()) print (H.hexdigest ())
Note: double-layer encryption.
Note: To add a Chinese key, convert the character type.
Python hashlib Module