Common Encryption Algorithms Explained: MD5, SHA, AES, and More
Overview of Encryption Algorithms
Encryption algorithms are mathematical functions used to secure data. They convert plaintext into ciphertext, which can only be decrypted with the correct key.
Hash Algorithms (One-Way)
MD5
MD5 produces a 128-bit hash value. While widely used historically, it is now considered cryptographically broken for security purposes but remains useful for checksums.
SHA Family
SHA (Secure Hash Algorithm) includes several variants:
- SHA-1: 160-bit hash, deprecated for security use
- SHA-256: 256-bit hash, widely used in security certificates
- SHA-512: 512-bit hash, highest security in SHA family
Symmetric Encryption
AES
Advanced Encryption Standard (AES) is the most widely used symmetric encryption algorithm. It supports key sizes of 128, 192, and 256 bits.
DES/3DES
Data Encryption Standard (DES) is an older algorithm now considered insecure. Triple DES (3DES) applies DES three times for improved security.
How to Choose
- For password hashing: Use SHA-256 or bcrypt
- For data encryption: Use AES-256
- For checksums: MD5 is acceptable
Real-World Application
In my work building authentication systems, I've used these algorithms extensively. Here's a practical example: when implementing user password storage, I always recommend using bcrypt or Argon2 with a salt, never MD5 or SHA-1. I once audited a legacy system that stored passwords using plain SHA-256 without salt — it was vulnerable to rainbow table attacks. We migrated all 50,000+ user passwords to bcrypt with proper salting.
For API authentication, I prefer HMAC-SHA256 for signing requests. It provides a good balance between security and performance. In one project, we used JWT tokens signed with RS256 (RSA + SHA-256) for microservice-to-microservice communication, which gave us both security and the ability to verify token authenticity without shared secrets.