What Is Hashing - Examples
What Is Hashing - Examples
Hashing is a process of converting data of any size into a fixed-size output (known as a hash
value, hash code, or digest) using a mathematical function called a hash function. Hashing is
widely used in computer science for data storage, retrieval, and security.
Characteristics of Hashing:
1. Fixed Output Size: No matter the input size, the output hash is of a fixed length.
2. Deterministic: The same input will always produce the same output.
3. Fast Computation: Hash functions are designed to be computationally efficient.
4. Irreversible: It's computationally infeasible to retrieve the original input from the hash.
5. Collision Resistance: It should be difficult to find two different inputs that produce the same
hash value.
Examples of Hashing:
1. Password Storage:
When storing user passwords, they are often hashed to ensure security.
Input: password123
Hash (using SHA-256):
ef92b778bafe771e89245b89ecbcbe47d85a92e986ed0858b6d8e3c327c5aee3
The actual password isn't stored, only its hash.
2. Data Integrity (Checksums):
Hashing is used to verify if data has been altered during transmission.
Example: A file's hash can be computed before and after transmission. If the hashes match, the
file has not been tampered with.
3. Hash Tables:
Hashing is used in data structures like hash tables for quick data retrieval.
Example: If "Alice" is hashed to 123 and stored at index 123, you can directly access Alice's
data using the hash.
4. Blockchain:
Hashing ensures the integrity of blocks in a blockchain.
Example: A block in a blockchain might hash its data (transactions) to a value like:
0000000000000000000acdf5b9877a4a
Common Hash Functions:
MD5 (Message Digest 5) – Now considered insecure for cryptographic purposes.
SHA-1 (Secure Hash Algorithm 1) – Also insecure for cryptographic use.
SHA-256 – Part of the SHA-2 family and widely used in modern applications.
CRC32 – Used in checksums for error detection.
Hashing is crucial in many applications, including databases, authentication, and digital
signatures.