File Checksum Calculator
Calculate file checksums to verify file integrity and detect corruption or tampering. Support for MD5, SHA-1, SHA-256, and SHA-512 hashes for comprehensive file verification.
Understanding File Checksums
| Purpose | How It Works |
|---|---|
| Integrity verification | Same file = same hash |
| Download verification | Compare hash to source |
| Duplicate detection | Identical files = identical hash |
| Tampering detection | Any change = different hash |
Common Checksum Algorithms
| Algorithm | Length | Speed | Use Case |
|---|---|---|---|
| MD5 | 32 chars | Fastest | Legacy, quick checks |
| SHA-1 | 40 chars | Fast | Git, legacy |
| SHA-256 | 64 chars | Fast | Recommended |
| SHA-512 | 128 chars | Moderate | Maximum security |
Calculate Checksums (Command Line)
``bash
# Linux/Mac
md5sum filename.zip
sha1sum filename.zip
sha256sum filename.zip
sha512sum filename.zip
# Mac alternative
shasum -a 256 filename.zip
# Windows
certutil -hashfile filename.zip MD5
certutil -hashfile filename.zip SHA256
`
Calculate Checksums (JavaScript)
`javascript
// Browser: File input to hash
async function calculateFileHash(file, algorithm = 'SHA-256') {
const arrayBuffer = await file.arrayBuffer();
const hashBuffer = await crypto.subtle.digest(algorithm, arrayBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
// Usage with file input
document.querySelector('input[type="file"]')
.addEventListener('change', async (e) => {
const file = e.target.files[0];
const hash = await calculateFileHash(file);
console.log(SHA-256: ${hash});
});
// Node.js
const crypto = require('crypto');
const fs = require('fs');
function calculateFileHashNode(filePath, algorithm = 'sha256') {
return new Promise((resolve, reject) => {
const hash = crypto.createHash(algorithm);
const stream = fs.createReadStream(filePath);
stream.on('data', data => hash.update(data));
stream.on('end', () => resolve(hash.digest('hex')));
stream.on('error', reject);
});
}
`
Verifying Downloads
1. Download the file
2. Get the official checksum from the source
3. Calculate your file's checksum
4. Compare them (must match exactly)
`bash
# Verify against expected hash
echo "expected_hash_here filename.zip" | sha256sum -c
``
When Checksums Don't Match
| Possible Cause | Solution |
|---|---|
| Incomplete download | Re-download |
| Corrupted file | Re-download |
| Wrong file version | Check version |
| Malicious tampering | Don't use file |
| Wrong algorithm | Verify algorithm used |