To create a SHA256 hash from a string in Ruby, you can use the OpenSSL library that comes with Ruby by default. Here is an example code snippet:
main.rb133 chars7 lines
In this code, we first require the openssl
library. Then we define the string that we want to hash. Finally, we use the OpenSSL::Digest::SHA256
class to create a SHA256 hash object, and then call the hexdigest
method on it, passing in the string we want to hash. The hexdigest
method returns the hexadecimal representation of the hash value as a string.
When you run this code, it will output the SHA256 hash of the string "Hello World!". You can replace this string with any other string that you want to hash.
gistlibby LogSnag