Generating Secure Hashes in Python
Secure hashes, message digests, or simply digest as they are popularly known are specific algorithms which take data of any type and any size and return a fixed bit length data that'll always be the same for the arbitrary data provided, in case the data is modified the hash will change vastly.
Secure hashes are used to verify message integrity, in cryptography, as many similar uses. You might have noticed that when you download some software or CD/DVD images (mainly open source) they also provide the md5sum with it, which can be used to verify the integrity of the downloaded file, if the MD5 digest of the downloaded file matches that of the original file it means that the downloaded file is same as the original file and the downloaded file is not corrupt.
There are a number of hashing algorithms, like MD4, MD5, SHA-1, SHA-2, etc. Some have been deprecated by it's successors, others may have weaknesses, as of now SHA-512 and RIPEMD-320 are the best hashing algorithms.
We'll be using the hashlib module provided by Python for generating all available secure hashes, all popular ones are available in the module. Follow the demo code below, to get an overview of the module & various algorithms' usage.
|All times are GMT +5.5. The time now is 05:44.|