Hashlib is a dedicated hash algorithm for the library, including MD5, SHA1, sha224, SHA256, sha384, sha512, the use of very simple, convenient.
MD5
The full name of MD5 is message-digest algorithm 5 (Information-Digest algorithm). 128-bit length. At present, MD5 is an irreversible algorithm.
It has high security. It corresponds to any string that can be encrypted into a unique fixed-length code.
SHA1
The full name of SHA1 is secure Hash algorithm (Secure Hash algorithm). SHA1 based on MD5, the data length is longer after encryption,
It produces a hash value of 160bit in length for inputs that are less than 264 in length. 32 more bits than MD5. Therefore, it is more secure than MD5, but SHA1 is slower than MD5.
Here's how to use the Hashlib:
1 2 ImportHashlib3 4A ="a test string"5 PrintHASHLIB.MD5 (Repr (a). Encode ('Utf-8'). Hexdigest ()6 PrintHASHLIB.SHA1 (Repr (a). Encode ('Utf-8'). Hexdigest ()7 Printhashlib.sha224 (Repr (a). Encode ('Utf-8'). Hexdigest ()8 PrintHASHLIB.SHA256 (Repr (a). Encode ('Utf-8'). Hexdigest ()9 Printhashlib.sha384 (Repr (a). Encode ('Utf-8'). Hexdigest ()Ten PrintHASHLIB.SHA512 (Repr (a). Encode ('Utf-8'). Hexdigest ()
Python3 using Hashlib for encryption