Web Development

Hashing is a fairly common thing to do in development. It may be used for hashing passwords, creating keys and many more. Ruby, like many other languages have these functions built-in.

First, require digest

require 'digest'

Ruby Hash with MD5 algorithm

pry(main)> Digest::MD5.hexdigest 'password'
=> "5f4dcc3b5aa765d61d8327deb882cf99"

Ruby Hash with SHA256 algorithm

pry(main)> Digest::SHA256.hexdigest 'password'
=> "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"

Ruby Hash with SHA512 algorithm

pry(main)> Digest::SHA512.hexdigest 'password'
=> "b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86"