create a sha512 hash from a string in ruby

To create a SHA512 hash from a string in Ruby, you can use the Digest class from the Ruby Standard Library. Here's an example:

main.rb
require 'digest'

string_to_hash = 'my secret message'

sha512_hash = Digest::SHA512.hexdigest string_to_hash

puts sha512_hash
128 chars
8 lines

This will output the SHA512 hash of the string_to_hash:

main.rb
8691bc161c6e7bd89318d840491542a060e79710b20208e8f238a91763f2c6a7fce6f8b6d94784d63b1e5e4296c2b9425d15828d26793fcc94caf60f6393d3c9
129 chars
2 lines

You can also pass a file instead of a string to calculate the SHA512 hash of that file:

main.rb
sha512_hash = Digest::SHA512.file('path/to/file').hexdigest
60 chars
2 lines

gistlibby LogSnag