Skip to content

Instantly share code, notes, and snippets.

@greenygh0st
Created January 3, 2016 07:16
Show Gist options
  • Select an option

  • Save greenygh0st/4844298dd9c9a5241bfc to your computer and use it in GitHub Desktop.

Select an option

Save greenygh0st/4844298dd9c9a5241bfc to your computer and use it in GitHub Desktop.
A few easy examples for getting hashes out of ruby from various sources
require 'digest'
#A few easy examples for getting hashes out of ruby from various sources
# Get SHA256 Hash of a file
puts Digest::SHA256.hexdigest File.read "data.dat"
# Get MD5 Hash of a file
puts Digest::MD5.hexdigest File.read "data.dat"
# Get MD5 Hash of a string
puts Digest::SHA256.hexdigest "Hello World"
# Get SHA256 Hash of a string using update
sha256 = Digest::SHA256.new
sha256.update "Hello"
sha256.update " World"
puts sha256.hexdigest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment