I’ve been having trouble with Ruby’s md5 function… The following code
snippet (file attached):
begin code
require ‘digest/md5’
md5=Digest::MD5.hexdigest(File.read(“C:\dc.log”))
puts md5 end code
produces completely different hash than any of the other tools I use
(MD5Win32 or winMD5Sum)… Am I not using the function correctly? Wtf is
being hashed?
produces completely different hash than any of the other tools I use
(MD5Win32 or winMD5Sum)… Am I not using the function correctly? Wtf is
being hashed?
You’re on Windows? perhaps you are dancing with text mode…
You’re on Windows? perhaps you are dancing with text mode…
Yes I am on Windows. Can you please elaborate on that?
Windows has a notion of “text files” and “binary files”; for the former
translation is done of CR/NL characters, and no translation is done for
the later. The MD5 utilities you’re using are putting their file
handles into binary mode and are seeing all of the actual octets of the
file’s contents; you’re seeing a different sequence of octets since your
file handle is in text mode.
produces completely different hash than any of the other tools I use
(MD5Win32 or winMD5Sum)… Am I not using the function correctly? Wtf is
being hashed?
ruby -e ‘require “digest/md5”; p
Digest::MD5.hexdigest(File.read(“C:\dc.log”, “rb”))’
I’m transforming a string.
How could I change a string to binary mode?
You don’t need to, it’s always a simple binary sequence.
Whether it got constructed correctly in the first place
is another thing though.
What’s with this thread being revived after nearly 4 months?
Can i just confirm whats going on here. You are loading the contents of
the file into memory and obtaining an MD5 checksum of the data in
memory? What is the difference between file.open and file.read also what
does the , “rb” do?