How to find the SHA1 hash of a string in Ruby

less than 1 minute read

To find the SHA1 hash of a string, first include the library digest/sha1 then use the code below, where password is the string we’re computing the hash of. In this exmaple we’ve set password to blah.

The snippet below assigns the SHA1 hash of our password (blah) to the variable sha1_pass.

require digest/sha1
# ... then later on ...
password = "blah"
sha1_pass = Digest::SHA1.hexdigest(password)

Tags:

Categories:

Updated: