Reading Time: 1 minutes
Creating Secure Hashes/Message Digests in Python using hashlib module
The builtin hashlib module provides an interface to create secure hashes/message digests of algorithms such as SHA1, SHA224, SHA256, SHA384, and SHA512 & RSA’s MD5. Each of these algorithms has a corresponding class in the module, the constructors of which, along with its hexdigest() methods produces secure hashes/message digests. The input is in bytes form and output is in hexadecimal digits.
>>> import hashlib # sha1 hash >>> hashlib.sha1(b"DjangoSpin: Articles for Pythonistas").hexdigest() '8fe8bdf0a83213d9d5ff43a5d3f3d951994e18e3' # sha256 hash >>> hashlib.sha256(b"DjangoSpin: Articles for Pythonistas").hexdigest() 'ea6f0fc02c4fac9f95cf0e03a18004b87c212c473eaa4bb3e1882255f0bbbdbf' # MD5 hash >>> hashlib.md5(b"DjangoSpin: Articles for Pythonistas").hexdigest() '59af3c14b3f913f37e18a096bad723c2'