Hashing is the process of transforming data of arbitrary size into a fixed-length value using a special algorithm called a hash function. The resulting value is known as a hash or hash value. Hashing is used to verify data integrity, store passwords, retrieve information, and perform various other tasks in information systems.
The main characteristic of hashing is that identical input data always produces the same result when processed by the same hash function. At the same time, even a small change in the original data can significantly alter the resulting hash.
For example, a hash can be calculated for a text document, image, executable file, or password. Depending on the algorithm, the result is represented as a sequence of characters of a specific length, regardless of the size of the original data.
How Hashing Works
A hash function takes input data and processes it according to a defined mathematical algorithm. The result is a fixed-length sequence of bits.
For example, the SHA-256 algorithm generates a 256-bit hash, typically represented as 64 hexadecimal characters. The original file, however, may be only a few bytes or several gigabytes in size.
The main properties of cryptographic hash functions include:
- Determinism. Identical input data always produces the same hash.
- One-way transformation. Recovering the original information from its hash is computationally difficult.
- Collision resistance. It should be computationally difficult to find two different sets of data that produce the same hash.
- Avalanche effect. A small change in the input data typically causes a significant change in the resulting hash.
- Fixed output length. The hash length is determined by the algorithm and does not depend on the size of the input data.
Not all hash functions provide cryptographic security. For example, algorithms used to distribute data in hash tables are primarily optimized for computational speed.
Where Hashing Is Used
Hashing is used in operating systems, databases, enterprise applications, cybersecurity tools, and network services.
One common application is file integrity verification. When transferring or downloading a file, its hash can be calculated and compared with a reference value obtained from a trusted source. If the values match, this provides a high degree of confidence that the file’s contents have not changed.
Another example is password storage. Instead of storing passwords in plaintext, systems can store values generated by specialized password hashing algorithms. During authentication, the entered password is verified against the stored value.
Hashing is also used in digital signatures, version control systems, and data deduplication technologies. In the latter case, hashes help identify identical blocks of information, eliminating the need to store duplicate copies. However, additional checks may be required to reliably confirm that the data is identical.
Common Hashing Algorithms
There are many hashing algorithms that differ in output length, performance, and cryptographic strength.
- MD5 generates a 128-bit hash. The algorithm was previously widely used for file verification and other purposes. However, due to discovered vulnerabilities, it is unsuitable for applications requiring cryptographic collision resistance.
- SHA-1 generates a 160-bit hash. This algorithm is also considered cryptographically obsolete because of practical collision attacks.
- SHA-256 belongs to the SHA-2 family and generates a 256-bit hash. It is used for data integrity verification, digital signatures, and various cryptographic protocols.
- SHA-3 is a separate family of cryptographic hash functions based on the Keccak algorithm. It uses a different internal construction from SHA-2.
- Argon2 is an algorithm specifically designed for password hashing. It allows computational and memory requirements to be adjusted, making large-scale password guessing more difficult. Argon2id, in particular, is recommended for password storage.
The choice of algorithm depends on the system’s intended purpose. Fast cryptographic hash functions are suitable for integrity verification, while specialized algorithms with configurable computational costs are preferable for secure password storage.
Hashing vs. Encryption: What’s the Difference?
Hashing and encryption serve different purposes, although both technologies involve data processing and information security.
- Encryption allows the original information to be recovered using the appropriate key. It is used to protect data confidentiality during storage and transmission.
- Hashing does not provide a reverse transformation. Its primary purpose is to generate a compact value that represents the original data.
For example, an encrypted document can be decrypted using the appropriate key. However, if a hash has been calculated for a document, its contents cannot be recovered from that hash through a conventional reverse operation.
Hashing itself does not provide confidentiality. If the original data is simple or predictable, an attacker may calculate hashes of possible input values and compare them with a known hash.