Hashing is the process of taking the input string of any length and turning it into cryptographic fixed output. Hashing is not an “encryption” we can’t retrieve the original data by decrypting the hash, it’s a one-way cryptographic function.
Properties that a cryptographic hash function needs to have in order to be considered secure:
- Computationally Efficient:
The hash function should be computationally efficient, which means that we should be able to get the output of the input string in a very short period of time. - Deterministic:
Deterministic means that the output for a specific input should always be same. This is critical because if you get different hashes every single time it will be impossible to keep track of the input. - Small Changes In The Input Changes the Hash:
If we make a small change in the input string, then the new hash produced is entirely different from the previous one. - Pre-Image Resistance:
The output of the hash function should not reveal the input string. A cryptographic hashing algorithms can receive any kind of input. The input can be numbers, letters, words, or punctuation marks. However, a hash function will always produce a fixed-length output. Regardless of what the input is, the output will be an alphanumeric code of fixed length. - Collision Resistant:
This property means that it should be practically impossible to find two different inputs which produces same output.
Every hash function with more inputs than outputs will necessarily have collisions. Consider a hash function such as SHA-256 that produces 256 bits of output from a large input. Since it must generate one of 2^256 outputs for each member of a much larger set of inputs, the pigeonhole principle guarantees that some inputs will hash to the same output. Collision resistance does not mean that no collisions exist; simply that they are hard to find. - Impossible To Reverse Engineer:
It must be impossible to reverse the mathematical process used to create the output. There is no inverse operation for a hash function.
