I apologize if this has already been answered, or if the answer is simpler than I realize, but I can't seem to figure out the following:
When I try to generate an md5 from a string, either with
echo -n "string" | md5sum | cut -f1 -d' '
or with
echo -n "string" | openssl md5
the result is not 32 characters, as I would expect, but rather 33 (using wc -c
).
So, I have a few questions:
- Why do both md5sum and openssl add a trailing space?
- Is there another way to generate an md5 hash without a trailing newline or space?
- Does the trailing space really matter?
Thank you all in advance.
Best Answer
It's 32 characters! The
md5sum
is adding a linefeed to the end. You can get rid of it like this:or you could do it like this:
You can tell when one of the commands is adding a newline because the 32 character string will show up on its own line. If no newline is present it should always show up like this: