MD5 Checksum of a String

D

Doug Jolley

The script shown in Exhibit A submits a test string to 3 different
methods for generating a hex MD5 checksum. The resulting output
obtained from running the script is shown in Exhibit B. The two
Ruby-based methods produce the same result; but, that result differs
from the result obtained from openssl. Can someone please tell me why
this is? I have read the archives relating to similar issues but those
seem to involve use of Windows, slightly differing files, etc. I don't
think any of those discussions apply to this issue. Thanks for any
input.

EXHIBIT A - Script

require 'digest/md5'
require 'md5'
test_string='My dog has fleas.'
puts(Digest::MD5.hexdigest(test_string))
puts(MD5.md5(test_string))
puts(`echo #{test_string} | openssl md5`)

EXHIBIT B - Output obtained from Running Script

ac91a8d0eccbd49f5b2b971db6620c3b
ac91a8d0eccbd49f5b2b971db6620c3b
e1eda5428bf76f362a0a7b5b91315ff8
 
J

Jonathan Nielsen

[Note: parts of this message were removed to make it a legal post.]

EXHIBIT B - Output obtained from Running Script

ac91a8d0eccbd49f5b2b971db6620c3b
ac91a8d0eccbd49f5b2b971db6620c3b
e1eda5428bf76f362a0a7b5b91315ff8

You will find that the third result is the MD5 for "My dog has fleas.\n" :

$ irb
irb(main):001:0> require 'digest/md5'
=> true
irb(main):002:0> Digest::MD5.hexdigest("My dog has fleas.\n")
=> "e1eda5428bf76f362a0a7b5b91315ff8"

The echo is appending a newline to the end of the string.

-Jonathan Nielsen
 
D

Doug Jolley

You will find that the third result is the MD5 for "My dog has fleas.\n"

Oops. My bad. I should have used 'echo -n'. So, it really was one of
the issues that had been discussed in the archive. I truly appologize.
Thanks for the input.

... doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top