Hashalgoritmer Förklarade: MD5, SHA-1, SHA-256, SHA-512
Quick Answer
MD5 och SHA-1 är brutna och får inte användas för säkerhets-känsliga ändamål. SHA-256 är nuvarande standard för integritetskontroller och signaturer. SHA-512 är snabbare på 64-bit CPU:er. Använd vår Hash Generator för att beräkna dem i din browser.
Introduction
En kryptografisk hash-funktion tar input av godtycklig storlek och producerar en faststorleks-digest som är deterministisk, snabb att beräkna, ogenomförbar att invertera, collision-resistant och avalanche-känslig (en bit-förändring ändrar ungefär hälften av output-bitarna). MD5 (128-bit), SHA-1 (160-bit), SHA-256 (256-bit) och SHA-512 (512-bit) är de fyra vanligaste hash-funktionerna, men deras säkerhetsegenskaper skiljer sig dramatiskt.
Step by Step
-
Understand the properties of a hash function
A good cryptographic hash is deterministic (same input always yields same output), fixed-size output, fast to compute, infeasible to reverse (pre-image resistance), infeasible to find two inputs with the same output (collision resistance), and avalanches (tiny input change flips ~50% of output bits).
-
Know the digest sizes
MD5 produces 128 bits (32 hex characters). SHA-1 produces 160 bits (40 hex characters). SHA-256 produces 256 bits (64 hex characters). SHA-512 produces 512 bits (128 hex characters). Longer digests reduce collision probability but increase storage size.
-
Learn why MD5 and SHA-1 are broken
Researchers found practical collision attacks against MD5 (2004) and SHA-1 (2017, SHAttered attack). Collisions let an attacker craft two different inputs with the same hash, breaking digital signatures and certificate authorities. Neither should be used for security.
-
Choose the right algorithm
For file integrity checks where speed matters more than security, MD5 or SHA-1 are still common. For any security-sensitive use (passwords, signatures, certificates, blockchain), use SHA-256 or SHA-512. For password storage, use a slow KDF like bcrypt, scrypt, or Argon2 —never raw SHA-256.
-
Compute and verify hashes
Use the Hash Generator to hash text with any algorithm, or File Hash to compute the hash of a local file. Compare the resulting digest against a known-good value to verify integrity —a single bit difference means the file was corrupted or tampered with.
Examples
MD5 of 'hello' (128-bit, 32 hex chars)
Input: hello
Output: 5d41402abc4b2a76b9719d911017c592
SHA-256 of 'hello' (256-bit, 64 hex chars)
Input: hello
Output: 2cf24dba5fb0d30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Avalanche effect —one character change
Input: hello vs Hello
Output: SHA-256('hello') starts 2cf24dba... while SHA-256('Hello') starts 185f8db3... —completely different despite one-bit input change
Common Problems
- Using MD5 or SHA-1 for password hashing: both are fast and broken, making brute-force and rainbow-table attacks trivial. Use bcrypt, scrypt, or Argon2 instead.
- Confusing hashing with encryption: hashing is one-way and irreversible; encryption is two-way. You cannot 'decrypt' a hash —you can only compare hashes.
- Ignoring length-extension attacks: MD5, SHA-1, SHA-256, and SHA-512 are all vulnerable to length-extension attacks when used as MACs. Use HMAC-SHA256 for message authentication.
- Comparing hashes with == instead of a constant-time comparison: timing leaks let attackers recover hashes byte by byte. Use a constant-time comparison in security code.
Tips
- Default to SHA-256 for new systems —it is fast, widely supported, and has no practical collision attack as of 2026.
- For password storage, use bcrypt with a work factor of 12+ (or Argon2id with 64MB memory) —never raw SHA-256, which is too fast against GPUs.
- When verifying file downloads, compare both the algorithm name and the digest —a SHA-1 hash is meaningless if the publisher only intended SHA-256.
- Use our File Hash tool to compute SHA-256 of large files locally without uploading —it streams the file through the Web Crypto API.