Somethings we need to utilize hashing algorithms in Ruby and/or Rails. Examples of this include verifying file integrity, hashing passwords, and much more. In this brief article we will show you how to hash data in various formats.
Calculate an MD5 Hash
The venerable MD5 algorithm is an older and simpler hashing algorithm. Please note that MD5 is considered insecure due to the fact it can be brute forced relatively quickly, so you should use this algorithm with extreme care. To use MD5, simply use the following code:
Calculate a SHA-1 Hash
SHA-1 hashes are much more secure. SHA-1 can be used for passwords and file hashing, but it’s recommended that you move to SHA-2 (SHA256, SHA384, and SHA512) as soon as you can as they are even more secure. SHA-1 is also an excellent choice for maintaining file integrity.
Calculate a SHA-2 hash: SHA256, SHA384, and SHA512
HA-2 includes a number of different digest lengths, with SHA-512 in theory being the most secure. Calculating these hashes is just as easy.
1 2 3 4 5
So far so good, That’s it!!! See ya!!! :)