Hash Generator: Complete Guide to MD5, SHA-1, SHA-256 and SHA-512
Complete guide to hashing algorithms: MD5, SHA-1, SHA-256, SHA-512, and HMAC. Learn how they work, when to use them, security considerations, and practical use cases for passwords, blockchain, and APIs.
Hash Generator: Complete Guide to MD5, SHA-1, SHA-256 and SHA-512
Cryptographic hashing algorithms are fundamental in modern information security. A hash generator transforms any input data (text, files, passwords) into a fixed-length string called a hash or digest. This function is one-way: it's impossible to retrieve the original input from the hash.
Our online Hash Generator supports major algorithms: MD5, SHA-1, SHA-256, SHA-512, and HMAC (Hash-based Message Authentication Code). Completely free, it processes everything in your browser to ensure maximum privacy.
How Cryptographic Hashing Works
A cryptographic hash algorithm takes variable-length input and produces fixed-length output. Essential properties are:
Fundamental Properties
- Determinism: Same input always produces same hash
- One-way: Impossible to calculate input from hash (one-way function)
- Avalanche Effect: Changing a single bit drastically changes the hash
- Collision Resistance: Extremely unlikely that two different inputs produce the same hash
- Speed: Fast hash calculation, slow to reverse (if possible)
Hashing Process
The process works like this:
- Input: Text or binary file of any size
- Padding: Input is divided into fixed-size blocks, adding padding if needed
- Compression: Each block passes through the algorithm's compression function
- Output: Final fixed-length hash (128 bits for MD5, 256 bits for SHA-256, etc)
Hash Algorithms: Detailed Comparison
MD5 (Message Digest 5)
- Hash Length: 128 bits (32 hexadecimal characters)
- Year: 1991 (Ronald Rivest)
- Speed: Very fast
- Security: ā COMPROMISED - Not secure for cryptographic applications
- Modern Use: Only non-cryptographic checksums, legacy systems
MD5 Example:
Input: "password"
MD5: 5f4dcc3b5aa765d61d8327deb882cf99
Why MD5 is Compromised: Practical collisions were found in 2004. Attackers can create two files with the same MD5 hash, making it unsuitable for digital signatures or password hashing.
SHA-1 (Secure Hash Algorithm 1)
- Hash Length: 160 bits (40 hexadecimal characters)
- Year: 1995 (NSA)
- Speed: Fast
- Security: ā ļø DEPRECATED - Not recommended for new applications
- Modern Use: Git (for commit IDs), legacy TLS
SHA-1 Example:
Input: "password"
SHA-1: 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
SHA-1 Status: Google and CWI Amsterdam demonstrated practical collisions in 2017 (SHAttered attack). Still used in Git but discouraged for security.
SHA-256 (SHA-2 Family)
- Hash Length: 256 bits (64 hexadecimal characters)
- Year: 2001 (NSA)
- Speed: Medium
- Security: ā SECURE - Current standard for cryptographic applications
- Modern Use: Bitcoin, TLS, digital signatures, password hashing
SHA-256 Example:
Input: "password"
SHA-256: 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
Why SHA-256 is Recommended: No known collisions, resistant to modern attacks, hardware supported (AES-NI), used in blockchain and PKI.
SHA-512 (SHA-2 Family)
- Hash Length: 512 bits (128 hexadecimal characters)
- Year: 2001 (NSA)
- Speed: Medium (faster than SHA-256 on 64-bit architectures)
- Security: ā VERY SECURE - Maximum available security
- Modern Use: High-security applications, government document signing
SHA-512 Example:
Input: "password"
SHA-512: b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86
HMAC (Hash-based Message Authentication Code)
HMAC combines a hash with a secret key for authentication:
- Function: HMAC(key, message) = hash(key + hash(key + message))
- Purpose: Verify data integrity AND authenticity
- Algorithms: HMAC-MD5, HMAC-SHA256, HMAC-SHA512
- Usage: JWT tokens, API signatures, webhook verification
HMAC-SHA256 Example:
Input: "message"
Key: "secret_key"
HMAC: 97d2a569059bbcd8ead4444ff99071f4c01d005bcefe0d3567e1be628e5fdcd9
Practical Use Cases
1. Password Storage
Problem: Never store passwords in plaintext in the database.
Solution: Hash the password before saving. At login, hash the input and compare with stored hash.
// ā WRONG - Plaintext password
INSERT INTO users (email, password) VALUES ('user@example.com', 'MyPass123');
// ā
CORRECT - Hashed password with salt
const bcrypt = require('bcrypt');
const saltRounds = 10;
const hash = await bcrypt.hash('MyPass123', saltRounds);
INSERT INTO users (email, password) VALUES ('user@example.com', '$2b$10$...');
Important Note: For passwords, use specific algorithms like bcrypt, Argon2, or PBKDF2, NOT just SHA-256. These are "slow hash" designed to resist brute-force.
2. File Integrity Verification
Verify that a file hasn't been modified or corrupted:
# Linux/Mac - Calculate SHA-256 of a file
sha256sum myfile.zip
a3c4f5b2... myfile.zip
# Compare with hash published by author
# If different ā file corrupted or tampered
Real case: Linux ISO downloads. The site provides SHA-256. After download, you verify the hash to ensure the file wasn't altered during transfer.
3. Digital Signatures
Hashing is used in digital signatures (RSA, ECDSA):
- Calculate SHA-256 of the document
- Encrypt the hash with private key
- Attach encrypted signature to document
- Recipient decrypts with public key and verifies hash
Advantages: Sign only the hash (small) instead of entire document (large), more efficient.
4. Blockchain and Cryptocurrencies
Bitcoin uses SHA-256 extensively:
- Block Hash: Each block is identified by its SHA-256 hash
- Proof of Work: Miners search for a nonce that produces a hash with N leading zeros
- Merkle Trees: Hash-based data structure for efficient verification
// Simplified - Bitcoin Mining
function mineBlock(transactions, difficulty) {
let nonce = 0;
while (true) {
const data = transactions + nonce;
const hash = sha256(sha256(data)); // Double SHA-256
if (hash.startsWith('0'.repeat(difficulty))) {
return { nonce, hash };
}
nonce++;
}
}
5. Content Addressing
Systems like IPFS, Git use hashes to identify content:
# Git - Commit ID is SHA-1 of commit object
git log
commit a7f3c21b8e9d4f2a1c5e6b8d9f0a1b2c3d4e5f67
# IPFS - File identified by hash of its content
ipfs add myfile.txt
QmXg9Pp2ytZ...
Advantage: Automatic deduplication - same content = same hash.
6. API Authentication
HMAC to sign API requests:
// Client - Sign the request
const timestamp = Date.now();
const message = `POST\n/api/resource\n${timestamp}\n${JSON.stringify(body)}`;
const signature = hmacSHA256(message, API_SECRET);
// Server - Verify signature
const expectedSignature = hmacSHA256(receivedMessage, API_SECRET);
if (signature === expectedSignature) {
// ā
Authentic request
}
Used by AWS Signature v4, Stripe webhooks, Shopify API.
7. Data Deduplication
Storage systems use hashes for deduplication:
# File A and File B have same content
sha256(FileA) = 5e884898da28...
sha256(FileB) = 5e884898da28...
# System saves only one physical copy
# Both files point to same block
Used in Dropbox, backup systems, ZFS filesystem.
Practical Guide: How to Use the Hash Generator
Step 1: Choose Algorithm
Open the Hash Generator and select:
- MD5: Only for legacy checksums, NOT for security
- SHA-1: Git commit IDs, legacy compatibility
- SHA-256: Modern standard for most uses
- SHA-512: Maximum security for critical applications
Step 2: Enter Data
You can hash:
- Text: Paste directly into input area
- File: Use "Upload File" button (local processing, no upload)
- Password: For testing, NOT for production (use bcrypt for real passwords)
Step 3: HMAC (Optional)
If you want to create an HMAC:
- Enable "Use HMAC" option
- Enter secret key
- Resulting hash will be authenticated with the key
Step 4: Copy Result
Hash is generated instantly. You can:
- Copy: One click to copy to clipboard
- Compare: Paste expected hash to verify equality
- Download: Save hash to TXT file
Security and Best Practices
ā Do's
- Use SHA-256+ for new cryptographic applications
- Add Salt when hashing passwords (prevents rainbow table attacks)
- Use slow algorithms (bcrypt, Argon2) for passwords, not SHA-256
- Verify hashes when downloading files from internet
- Use HMAC to authenticate messages with shared key
ā Don'ts
- DON'T use MD5 or SHA-1 for security (only legacy)
- DON'T hash passwords without salt (vulnerable to rainbow tables)
- DON'T use only SHA-256 for passwords (too fast, use bcrypt)
- DON'T assume hash = encryption (hash is one-way, encryption is two-way)
- DON'T share HMAC keys publicly
Salt and Pepper Strategies
Salt: Random value added to password before hashing.
// Without salt (VULNERABLE)
hash('password123') ā always same hash
Attacker uses rainbow table to crack
// With salt (SECURE)
hash('password123' + 'random_salt_xyz') ā unique hash per user
Rainbow table useless
Pepper: Secret key added to all passwords (stored separately from DB).
hash = bcrypt(password + salt + PEPPER_FROM_ENV)
Modern best practice: bcrypt already includes salt automatically. Argon2 is state of the art (2023).
Performance and Hardware Acceleration
Algorithms have different performance:
| Algorithm | Speed (MB/s) | 32-bit CPU | 64-bit CPU | Hardware Acceleration |
|---|---|---|---|---|
| MD5 | ~600 | ā | ā | No |
| SHA-1 | ~550 | ā | ā | Limited |
| SHA-256 | ~150 | ā | ā | SHA-NI (Intel/AMD) |
| SHA-512 | ~200 | Slow | ā Fast | SHA-NI (Intel/AMD) |
Note: SHA-512 is faster than SHA-256 on 64-bit CPUs thanks to native 64-bit operations.
Frequently Asked Questions (FAQ)
What's the difference between hash and encryption?
Hash is a one-way function: you can't retrieve input from output. Used for integrity and verification. Encryption is two-way: you can decrypt with the correct key. Used for confidentiality. Examples: SHA-256 (hash), AES (encryption).
Can I "decrypt" a hash?
No. Hashing is not reversible by design. However, weak hashes (MD5) can be "cracked" using rainbow tables (precomputed databases) or brute-force. That's why we use salt and slow algorithms for passwords.
Why is MD5 still used if it's insecure?
MD5 is fast and sufficient for non-cryptographic checksums: verifying file integrity in trusted environments, cache keys, unique identifiers. It should NOT be used for passwords, digital signatures, or any security application.
Is SHA-256 sufficient for hashing passwords?
No. SHA-256 is too fast (~150 MB/s), allowing billions of attempts per second with GPUs. For passwords use bcrypt (10-100 ms per hash), Argon2 (winner of Password Hashing Competition 2015), or scrypt.
What is a rainbow table and how does it work?
A rainbow table is a precomputed database of common hashes. Example: contains hashes of all passwords from 1-8 characters. Attacker compares stolen hash with table to find original password. Defense: unique salt per password makes rainbow tables useless.
When to use HMAC instead of simple hash?
Use HMAC when you need to verify both integrity and authenticity. Plain hash only verifies integrity. HMAC with secret key proves only who possesses the key generated that value. Examples: JWT, API signatures, webhook verification.
Is SHA-3 better than SHA-2?
SHA-3 (2015) uses Keccak algorithm, different from SHA-2. It's theoretically more secure but not because SHA-2 is compromised. SHA-256/SHA-512 are still standard. SHA-3 is alternative for cryptographic diversification and some specific use cases (sponge construction).
Are hashes quantum-safe?
Cryptographic hashes are relatively resistant to quantum computers. Grover's algorithm halves security: SHA-256 goes from 256-bit to 128-bit quantum security (still secure). SHA-512 remains at 256-bit. More concerning is asymmetric encryption (RSA, ECDSA).
Related Resources
Explore other useful THEJORD tools:
- Base64 Encoder/Decoder: Encode data for secure transport, complementary to hashing
- JSON Formatter: Format JSON before calculating hash for consistency
- Diff Checker: Compare hash outputs to verify changes
- URL Encoder: Encode hashes for use in URL query parameters