Overview
MD5 (Message Digest Algorithm 5) is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value. While it was once commonly used for security purposes, it is now considered cryptographically broken and unsuitable for security applications. However, it is still used for non-security-critical purposes like file integrity verification.
Technical Details
Hash Characteristics
- 128-bit output
- Fixed length
- One-way function
- Deterministic
Key Features
- Fast computation
- Wide support
- Simple implementation
- Not secure for cryptography
Common Uses
- File integrity checks
- Checksums
- Non-critical verification
- Legacy systems
Examples
String Hash
Input: "Hello, World!" MD5: 65a8e27d8879283831b664bd8b7f0ad4
File Hash
File: example.txt MD5: d41d8cd98f00b204e9800998ecf8427e
Implementation
JavaScript Example
// Using crypto-js library
const CryptoJS = require('crypto-js');
// Hash a string
const hash = CryptoJS.MD5('Hello, World!').toString();
console.log(hash); // "65a8e27d8879283831b664bd8b7f0ad4"
// Hash a file (in Node.js)
const fs = require('fs');
const crypto = require('crypto');
const fileBuffer = fs.readFileSync('example.txt');
const hashSum = crypto.createHash('md5');
hashSum.update(fileBuffer);
const hex = hashSum.digest('hex');
console.log(hex);