Overview
- MD5 is a message digest, a cryptographic hash of 128 bits.
- MD5 is obsolete as a secure hash meaning it can be broken in sub second durations or in few seconds using collision attacks and chosen prefix collision attacks.
- Because of this, it cannot be used to for checking data integrity, digital signatures and storage of passwords.
- MD5 is still useful as a file integrity check mechanism when no intentional threats are expected.
Example
# Example Python program that generates a
# MD5 has for a given string using the
# hashlib module of Python
import hashlib
# Create a MD5 digest for a text
text1AsBytes = b"The wheel on the bus goes round and round"
md5hash = hashlib.md5(text1AsBytes)
print("The message:")
print(text1AsBytes)
print("The MD5 message digest:")
print(md5hash.hexdigest())
# Try md5 digest for the same text with only a letter
# changed
text2AsBytes = b"The wheel on the bus goes round and sound"
md5hash = hashlib.md5(text2AsBytes)
print("The message:")
print(text2AsBytes)
print("The MD5 message digest:")
print(md5hash.hexdigest())Output
The message:
b'The wheel on the bus goes round and round'
The MD5 message digest:
6964bf39b0c4b9b0786c3151d561263a
The message:
b'The wheel on the bus goes round and sound'
The MD5 message digest:
d0542ac42d059fc7187145ea507ca368