Finding the necesity to use a hashing algorithm is a common situation when we are creating our apps or proyects. If you know them or not, this article will explain you (briefly) what is hashing and how much useful it is.
What is hashing?
A criptographic function (usually knowed like "hash") is a mathematical algorithm that transforms the input of data in a new serie of characters with fixed length. For the same input, the algorithm will return the same hash output. This function is deterministic.
If our input is the string "ShinyCode", the equivalent hash (using SHA256) will be:
9f438a381759a5c663ea3cca194603c7dd08eccf1c6d152da7b743b057d7bd4f
Different types of Algorithms
But you need to know that its not only one algorithm that does that magic ๐ง. There are different types of hashing functions, which means that the generated string will vary according to each algorithm. The most popular hashing functions are for example MD5 or SHA-256 (256 bits).
So... Should i make my own Hashing Algorithm?
The direct answer is NO. ๐ต
This algorithms, as described up, are very complex mathematic functions. They map the data that we need to encrypt in a unique string and as you can imagine, that's not a simple process. Remember, Don't reinvent the wheel because the use case of the generated hashes may interact with sensitive data, so you dont want problems or bugs there.
Use cases for Hashes
You may be thinking in what cases use this hashes. Why i need to encrypt the data like that?
Here are some of them:
- Integrity: Because the generated hash of an input is like fingerprints. For example, when your data goes through transformation processes or when it is moved, you have the generated hash that you can use to compare and ensure that no problems were introduced.
- Comparation: Making comparations between hashes helps you with integrity, but also in other scenarios. For example, if you save the hash of a photo, and later that photo has changed, you can extract a new hash and compare to the old to know if there were changes.
- Security: Another common case is for sensitive data. For example, it's not good to store passwords in plain text in your database. The best way to save the passwords, is generating a hash for it and saving the hashs. Now, your data is encrypted and can't be stolen easily ๐.
Conclusion
The time always comes to need to generate hashs in your application. It's important to know what they are and how to use them. Exploring more about this topic may be very helpful.
The libraries to use for generating hashs vary for one language to another. For example if you are a Javascript developer, you can try bcrypt and see how this works in a practical manner.
I hope this article has been useful for your future projects.
Thanks for read ๐.