Secure Hash Algorithms
lastmod 2025-01-15created 2015-03-124 edits
The SHA (Secure Hash Algorithm) functions are a family of related cryptographic hash functions. They were first designed by the US National Security Agency (NSA) in 1993 and designated as a US national standard. The first function in the SHA family is officially called SHA, but it is also called SHA-0 to distinguish it from the functions designed later. Two years later, SHA-1, a variant of SHA-0, was published, and after that four more variants were published: SHA-224, SHA-256, SHA-384, and SHA-512. These are sometimes collectively called SHA-2.
SHA-1 is the most widely used of the SHA functions and is used in many security protocols and programs, such as TLS, SSL, PGP, SSH, and IPSec. SHA-1 is also used in place of MD5, which was previously in wide use. Some recommend using SHA-256 or stronger algorithms for more critical technologies.
Attacks on SHA-0 and SHA-1 have already been found. No attacks on SHA-2 have been found yet, but experts point out that attacks may be found because the SHA-2 functions use methods similar to SHA-1. The US National Institute of Standards and Technology (NIST) held a public competition for candidates for a new cryptographic hash algorithm called SHA-2.
Command line
You can use the openssl command line or sha256sum.
| WARNING |
| When using echo on the command line, a newline is forcibly appended, so you must add the |
JavaScript hashing speed comparison: MD5 vs SHA-256
- MD5 is slower than SHA-256 and less secure.
- MD5 is a hash algorithm used in the past and is no longer cryptographically secure.
- SHA-256 produces a 256-bit hash output and offers stronger security.
- In the tests, SHA-256 was also better than MD5 in processing speed.
- The tests were run with modern JavaScript runtimes.
- Tests were run on ARM and Intel systems using Bun 1.31 and Node.js 23.
- Performance was compared on Apple M2, Intel Ice Lake, and Amazon Graviton 4 systems.
- SHA-256 performs faster on modern processors.
- On the Apple M2 system, MD5 reached 0.7 GB/s and SHA-256 reached 2.6 GB/s.
- On Intel and ARM-based systems as well, SHA-256 outperformed MD5.
- Modern processors provide cryptographic extensions to accelerate SHA-256.
- It is recommended not to use MD5 in practice.
- It is safer to use SHA-256 as a strong alternative to MD5, which has security problems.
- SHA-256 provides both security and performance, and ensures encryption and data integrity.