MD5 Checksum of a String

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

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 N.

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