What is MD5?
MD5 turns any file or piece of text into a string of 32 letters and numbers. It’s an old hash function that attackers broke years ago, so it’s no longer safe for anything security-related. It still shows up all over the place for everyday jobs like checking whether a file got damaged on the way to your computer.
MD stands for Message Digest. Ron Rivest designed MD5 in 1991 as the fifth algorithm in his series, replacing MD4 after people found weaknesses in it. MD5 always outputs 128 bits of binary, which get written as 32 hexadecimal characters. Here’s the MD5 of the word “hello”:
5d41402abc4b2a76b9719d911017c592
A secure hash should make it practically impossible to find two different inputs that produce the same output, which is called a collision. Xiaoyun Wang’s team showed how to find MD5 collisions in 2004 and the attacks kept getting cheaper after that. Researchers used MD5 collisions in 2008 to forge a certificate authority certificate that could vouch for any website and still look legitimate to web browsers. Security researchers caught the Flame malware in 2012 and found it had used the same trick to fake a Microsoft code-signing certificate so it could pass itself off as a Windows update. Stronger hash functions like SHA-256 took over for security work because of attacks like these.
MD5 is still perfectly fine when nobody is trying to trick you. It’s fast and its output is short, so people use it to spot files that got corrupted by accident, build cache keys, find duplicate files and generate ETags that tell a browser whether a file on a server has changed. You can compute one in the terminal with a single command:
md5 photo.jpg # macOS
md5sum photo.jpg # Linux
Never use MD5 for passwords. Plenty of older sites stored passwords as plain MD5 hashes with no salt, which meant the same password always produced the same hash. Attackers cracked most of those passwords soon after each database leaked because MD5 is so quick to compute. Use bcrypt for passwords and SHA-256 for anything where security matters.