-
-
Save yumitsu/727018f97f1e1ceb3f6153ebe951a880 to your computer and use it in GitHub Desktop.
Hash of files an strings with Ruby using MD5 and SHA256
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
# 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