p99will
p99will

Reputation: 250

Is Unix md5 different to python's hashlib.md5?

I run echo lol | md5 in Mac Terminal and it returns: 59bcc3ad6775562f845953cf01624225

But then I run print hashlib.md5("lol").hexdigest() in python 2.7 and I get: 9cdfb439c7876e703e307864c9167a15

What am I doing wrong?

Upvotes: 2

Views: 1046

Answers (1)

metatoaster
metatoaster

Reputation: 18908

echo appends a newline at the end by default, so it will give a different hash.

In python, with the newline ending

>>> print hashlib.md5("lol\n").hexdigest()
59bcc3ad6775562f845953cf01624225

Standard echo command, with the newline ending omitted.

$ echo -n lol | md5sum -
9cdfb439c7876e703e307864c9167a15  -

Upvotes: 10

Related Questions