SHA-1 Hash Generator
Generate SHA-1 hashes for data verification and legacy compatibility. SHA-1 produces a 160-bit (40 character hexadecimal) hash. While deprecated for security use, SHA-1 is still used in Git and some legacy systems.
Understanding SHA-1
| Property | Value |
|---|---|
| Output length | 160 bits (20 bytes) |
| Hex representation | 40 characters |
| Security | Deprecated (collisions found) |
| Speed | Fast |
| Use case | Git commits, legacy systems |
SHA-1 Implementation
``javascript
// Using Web Crypto API
async function sha1(text) {
const encoder = new TextEncoder();
const data = encoder.encode(text);
const hashBuffer = await crypto.subtle.digest('SHA-1', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
// Node.js
const crypto = require('crypto');
function sha1Node(text) {
return crypto.createHash('sha1').update(text).digest('hex');
}
// Example
await sha1('hello world');
// "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"
`
Git and SHA-1
Git uses SHA-1 for commit identifiers:
`bash
# View commit hash
git log --oneline
# a1b2c3d (HEAD -> main) Latest commit
# SHA-1 is used for:
# - Commit IDs
# - Tree objects
# - Blob objects
# - Tag objects
``
SHA-1 Security Status
| Year | Event |
|---|---|
| 2005 | Theoretical weaknesses found |
| 2017 | First practical collision (SHAttered) |
| 2019 | Chosen-prefix collision |
| 2020 | Attack cost reduced to ~$45k |
Migration from SHA-1
| Use | Migrate To |
|---|---|
| Certificates | SHA-256 (required since 2017) |
| Code signing | SHA-256 |
| Data integrity | SHA-256 |
| Git | SHA-256 (Git 2.29+) |