← Back to Blog

Choosing a Text Hash Tool: Where MD5, SHA Families, and BCrypt Diverge

What Is a Hash?

A hash maps arbitrary-length input to a fixed-length output (digest) via a one-way function. A good cryptographic hash is: deterministic (same input → same output), avalanche (one bit change flips output completely), collision-resistant (hard to find two inputs with the same digest), and one-way (hard to reverse).

But "one-way" is not "unbreakable" — for short or common strings, attackers reverse them with rainbow tables or brute force. So the hash function must match the job.

Four Jobs, Four Choices

Job Recommended Why
File integrity check MD5 / SHA-256 Fast and reproducible; goal is detecting corruption, not thwarting attackers
Data fingerprint / dedup SHA-256 Negligible collision probability, stable output
Tamper-evident signing SHA-256 / SHA-512 Verify content unchanged (pair with a key via HMAC)
Password storage BCrypt / Argon2 Slow hash + salt, designed to resist brute force

MD5 / SHA-1: Unsafe but Still Useful

MD5 (128-bit) and SHA-1 (160-bit) have demonstrable collision attacks and must never be used for security tokens, signatures, or certificates. But for "file dedup", "cache keys", or "non-adversarial checksums" — where no attacker is trying to fool you — they remain fast and perfectly fine.

Rule of thumb: if an attacker could craft inputs to deceive you, don't use MD5/SHA-1. Otherwise (e.g. local file comparison) it's acceptable.

SHA-2 Family: The Default Safe Choice

SHA-256 / SHA-384 / SHA-512 belong to SHA-2. No practical collision attack is known; they are the default for most security scenarios:

  • SHA-256: 256-bit output, the most universal — blockchains, certificates, Git commits, file signing.
  • SHA-512: 512-bit output, faster on 64-bit CPUs, slightly better against length-extension attacks.

Why Passwords Must Not Use SHA

SHA's design goal is speed — its strength, and a fatal flaw for password storage. An attacker with one GPU computes billions of SHA hashes per second, breaking weak passwords instantly.

Password storage needs a slow hash + salt:

  • BCrypt: adaptive cost factor, slows as hardware improves; salts automatically.
  • Argon2: 2015 Password Hashing Competition winner, memory-hard against GPU/ASIC.
  • SCrypt: memory-hard, also resists hardware acceleration.

This site's hash-text is a general-purpose one-way hash tool for checksums, fingerprints, and signature verification. For password storage, use a dedicated BCrypt-class scheme — do not "just hash the password and store it" here.

Hash ≠ Encryption

  • Encryption (AES, etc.): reversible — a key restores the plaintext → protects confidentiality.
  • Hash (SHA/MD5/BCrypt): one-way — not reversible → verifies integrity / generates fingerprints.

Need the data back? Use encryption, not a hash.

Best Practices

  1. Use SHA-256 for checksums/fingerprints; don't fall back to MD5 for security uses.
  2. Use HMAC-SHA256 for tamper evidence; let the key participate in the hash.
  3. Use BCrypt/Argon2 for passwords; never bare SHA.
  4. Don't treat a hash as encryption: if you need to recover data, use AES.
  5. No random salt for reproducible scenarios (file checksums); always salt passwords.

Frequently Asked Questions

MD5 还能用吗?

用于「完整性校验 / 非安全场景」(如文件去重、缓存键)仍可用,因为它快且无碰撞攻击风险影响这些用途。但任何涉及「防篡改 / 防伪 / 安全标识」的场景都不要用 MD5/SHA-1,改用 SHA-256。

SHA-256 和 SHA-512 怎么选?

两者都安全。SHA-256 输出 256 位,在 32 位/移动端和高并发校验中更省;SHA-512 输出 512 位,64 位平台上更快且抗长度扩展攻击略好。普通场景选 SHA-256 即可。

为什么密码不能用 SHA 存储?

SHA 系列设计目标是「快」,攻击者可用 GPU 每秒算数十亿次。密码存储需要「慢哈希」+ 盐(salt),如 BCrypt/Argon2/SCrypt,故意拖慢单次计算以抵抗暴力破解。本站 hash-text 工具是通用哈希,不是密码存储方案。

哈希和加密是一回事吗?

不是。加密可逆(有密钥可还原明文),哈希单向(理论上不可还原)。哈希用于「验证完整性 / 生成指纹」,加密用于「保护机密」。需要还原数据请用 AES(本站 AES 加密工具)。

加盐(salt)是什么?

salt 是在哈希前拼接到原文的随机值,使相同明文产生不同哈希,阻止彩虹表批量反查。通用哈希工具通常不自动加盐(因为要可复现),密码存储的 salt 由 BCrypt 等专业方案自动处理。

← Back to Blog