Why is the output of hashlib.md5().hexdigest() different than md5sum and openssl output?
$ echo "test string" | md5sum
f299060e0383392ebeac64b714eca7e3 -
$ echo "test string" | openssl dgst -md5
(stdin)= f299060e0383392ebeac64b714eca7e3
$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from hashlib import md5
>>> print(md5("test string").hexdigest())
6f8db599de986fab7a21625b7916589c
I noticed this while trying to generate an md5 digest for use with Gravatar. The Python hashlib output works but the md5sum and openssl outputs do not.
echo adds an implicit newline by default.
$ echo -n "test string" | openssl dgst -md5
(stdin)= 6f8db599de986fab7a21625b7916589c