11

I have installed the "md5sum" utility on my Mac and there was also a "md5" binary pre-installed in /sbin.
My problem and question is this: "Isn't MD5 a standard algorithm?"
Because I get different hashes for a string using these utilities
Are there any differences in these utilities' implementations? Example:

Mehdi-MacBook-Pro:~ mehdi$ md5 -s Hello
MD5 ("Hello") = 8b1a9953c4611296a827abf8c47804d7

Mehdi-MacBook-Pro:~ mehdi$ echo Hello | md5sum
09f7e02f1290be211da707a266f153b3  -
15

By default, echo leaves a trailing newline. So you need to do:

echo -n Hello | md5sum

8b1a9953c4611296a827abf8c47804d7
5

Consider this:

$ echo Hello | md5sum 
09f7e02f1290be211da707a266f153b3  -
$ echo -n Hello | md5sum
8b1a9953c4611296a827abf8c47804d7  -

In the first case, you hash six bytes, for 'H', 'e', 'l', 'l', 'o' and a newline character (0x0A). In the second, you don't include the newline character, which mimics what OS X md5 utility does with the argument -s.

  • 1
    +1. You might mention that this problem bites a lot of people: 1, 2, 3, etc. – David Cary Aug 15 '14 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.