Hello all:
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?
···
--
Posted via http://www.ruby-forum.com/.
Denys Yakhnenko wrote:
Hello all:
I've been having trouble with Ruby's md5 function... The following code
snippet (file attached):
I get Application error (Rails) if I try to include the file as
attachment...
···
--
Posted via http://www.ruby-forum.com/.
File.read is a bad choice on Windows. It should be avoided if at all
possible. Do this instead:
puts Digets::MD5.hexdigest(File.open("C:\\dc.log", "rb") { |f| f.read })
-austin
···
On 12/5/06, Denys Yakhnenko <dyakhnenko@linkp.com> wrote:
Hello all:
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***
--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
* austin@halostatue.ca * http://www.halostatue.ca/feed/
* austin@zieglers.ca
Denys Yakhnenko wrote:
***begin code***
require 'digest/md5'
md5=Digest::MD5.hexdigest(File.read("C:\\dc.log"))
puts md5
***end code***
For me, on a Linux box, with a random file, it works fine. Are you
sure your file is read properly ? See:
22:47 vincent@tanyaivinco ~ irb1.8
require 'digest/md5'
=> true
md5=Digest::MD5.hexdigest(File.read("qt-enum.patch"))
=> "c15a3cfc054d9af29b40a37805c27dbf"
%
22:48 vincent@tanyaivinco ~ md5sum qt-enum.patch
c15a3cfc054d9af29b40a37805c27dbf qt-enum.patch
Vince
···
--
Vincent Fourmond, PhD student
http://vincent.fourmond.neuf.fr/
maybe only part of your data ??
try
require 'digest/md5'
buf = open("C:\\dc.log","rb"){|f| f.read}
md5 = Digest::MD5.hexdiges buf
puts md5
-a
···
On Wed, 6 Dec 2006, Denys Yakhnenko wrote:
Hello all:
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?
--
if you want others to be happy, practice compassion.
if you want to be happy, practice compassion. -- the dalai lama
Denys Yakhnenko wrote:
md5=Digest::MD5.hexdigest(File.read("C:\\dc.log"))
produces completely different hash than any of the other tools I use
Open the file in binary mode:
ruby -e 'require "digest/md5"; p Digest::MD5.hexdigest(File.read("C:\\dc.log", "rb"))'
Clifford Heath.
Denys Yakhnenko wrote:
I get Application error (Rails) if I try to include the file as
attachment...
Ruby's output:
C:\ruby\my>test2.rb
68aad1424a2389dcd991b400a9b32934
MD5 tools output...
8c149edff1d09df3a33871dc5c362906
I apologize for this many messages.
Denys
···
--
Posted via http://www.ruby-forum.com/.
Urabe Shyouhei wrote:
You're on Windows? perhaps you are dancing with text mode...
Yes I am on Windows. Can you please elaborate on that?
···
--
Posted via http://www.ruby-forum.com/.
Clifford Heath wrote:
Denys Yakhnenko wrote:
md5=Digest::MD5.hexdigest(File.read("C:\\dc.log"))
produces completely different hash than any of the other tools I use
Open the file in binary mode:
ruby -e 'require "digest/md5"; p
Digest::MD5.hexdigest(File.read("C:\\dc.log", "rb"))'
Clifford Heath.
I'm transforming a string.
How could I change a string to binary mode?
Thanks
Abon
···
--
Posted via http://www.ruby-forum.com/.
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?
Many thanks
Austin Ziegler wrote:
···
On 12/5/06, Denys Yakhnenko <dyakhnenko@linkp.com> wrote:
***end code***
File.read is a bad choice on Windows. It should be avoided if at all
possible. Do this instead:
puts Digets::MD5.hexdigest(File.open("C:\\dc.log", "rb") { |f| f.read
})
-austin
--
Posted via http://www.ruby-forum.com/.
Denys Yakhnenko wrote:
Urabe Shyouhei wrote:
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.
See the IO#binmode method docs as well.
···
--
Posted via http://www.ruby-forum.com/.
Bontina Chen wrote:
Clifford Heath wrote:
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?
Clifford Heath.