Let us consider four names Yashwanth, Sandeep, Anudeep and Vasanth are present in a database. If we do a normal database search, it would have to look character upon character. But, if we consider that the above strings of characters are hashed and the keys are allotted as follows
Yashwanth 7988, Sandeep 6116, Anudeep 6558 and Vasanth 6200.
The search would initially compute the hash value using the same algorithm used to generate the hash values and then compare it with the hash values stored in the database. It would be much faster since each digit in the four digits has only 10 possibilities than compared to an unknown string with each letter having 26 possibilities.
The hashing algorithm is called the hash function. The hashing mechanism is also used to encrypt and decrypt digital signatures. A good hashing algorithm should not produce the same hash values for more than one input. If it happens, it is called a collision.
Let us learn about hash functions in cryptography. These are called Cryptographic Hash Functions.
Cryptographic hash functions are used in digital signatures, message authentication codes and many other methods of authentication.
Let's head towards some of the famous Cryptographic Hash Functions.
Message-Digest 5(MD-5) Algorithm:
It was designed by Ronald Rivest in the year of 1992. It produces a 128-bit hash value. In 1996, a security flaw which did not seem to be that fatal. In 2004, it was found that the MD-5 algorithm was not collision-resistant. Hence, this was discontinued later as it could not rely upon for digital signatures or SSL certificates.
Secure Hash Algorithms(SHA)
These are a set of algorithms publishes by the National Institute of Standards and Technology(NIST). It has four versions namely SHA-0, 1, 2 and 3. SHA-0 was published in the year of 1993. It produces a 160-bit hash value. A full collision was found in the year of 2004. The complexity of the system started reducing day-by-day. The algorithm's usage was reduced due to security concerns. SHA-2 was designed by the United States National Security Agency(NSA). It has six functions with hash values as follows: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256. It is used in security applications including TLS(Transport Layer Security) and SSL(Secure Sockets Layer). Cryptocurrencies like Bitcoin use this kind of security for verifying transactions. SHA-3 was published in the year of 2015 by NIST. It is internally different when compared to the remaining algorithms.
Advantages and Disadvantages of Hashing
The main advantage of Hash Function is the speed and disadvantage being the collisions that are unavoidable.
Hashing and Encryption
When encrypted, it can also be decrypted with a proper key. It is a two-way function. It is not in the case of Hashing because Hashing is a one-way function. It is not reversible with a well-devised algorithm. Hence, Hashing with the well-devised algorithm is considered to be more secure than Encryption.