To create a SHA1 hash from a string in Ruby, you can use the OpenSSL library.
main.rb144 chars8 lines
Output:
main.rb71 chars2 lines
Here, we require the openssl
library and define a string
variable containing the text we want to hash.
Next, we use the OpenSSL::Digest::SHA1
class to create a SHA1 hash object. We then pass our string
variable into the hexdigest
method of the SHA1 hash object to generate the SHA1 hash in string format.
Finally, we print the SHA1 hash using puts
.
gistlibby LogSnag