
Hash Functions Explained: MD5, SHA-1, SHA-256, and When to Use Each
Hash Functions Explained: MD5, SHA-1, SHA-256, and When to Use Each What is a Hash Function? A hash function converts input of any size into a fixed-length "fingerprint." The same input always produces the same output. You cannot reverse a hash. // Node.js const crypto = require ( ' crypto ' ); console . log ( crypto . createHash ( ' sha256 ' ). update ( ' hello ' ). digest ( ' hex ' )); // Output: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 console . log ( crypto . createHash ( ' md5 ' ). update ( ' hello ' ). digest ( ' hex ' )); // Output: 5d41402abc4b2a76b9719d911017c592 Comparison Table Algorithm Output Length Speed Security Use Case MD5 128-bit Fast ❌ Broken File checksums (non-security) SHA-1 160-bit Fast ❌ Deprecated Git commits (historical) SHA-256 256-bit Medium ✅ Secure General-purpose hashing bcrypt Variable Slow ✅ Secure Password storage Argon2 Variable Slow ✅ Best Password storage (recommended) Why MD5 and SHA-1 Are Broken // MD5 collision example (si
Continue reading on Dev.to Webdev
Opens in a new tab




