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.
Tags:cryptography | hashing | md5 | python. The MD5, defined in RFC 1321, is a hash algorithm to turn inputs into a fixed 128-bit (16 bytes) length of the hash value. Note. MD5 is not collision-resistant – Two different inputs may producing the same hash value.
hexdigest() : the digest is returned as a string object of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.
echo
adds an implicit newline by default.
$ echo -n "test string" | openssl dgst -md5
(stdin)= 6f8db599de986fab7a21625b7916589c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With