質問

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?

役に立ちましたか?

解決

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  -
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top