Bob
Bob

Reputation: 23

md5sum returns different values with "same" strings

md5sum function returns different values in the same string In this case

>echo -n Bob | md5sum 
 2fc1c0beb992cd7096975cfebf9d5c3b

But in this other case .

>md5sum <<< Bob 
a2eae7400008e77790c3272f754a14db

What happened here? Some advices?

Upvotes: 0

Views: 721

Answers (2)

chepner
chepner

Reputation: 530833

The here string includes an implicit newline character (0x0a in hexadecimal). Compare

$ echo -n Bob | hexdump
0000000 42 6f 62
0000003

with

$ hexdump <<< "Bob"
0000000 42 6f 62 0a
0000004

You are actually computing the MD5 checksum for two different strings, hence the difference in output. If you don't suppress the newline from the output of echo, you get the same result as with the here string:

$ echo Bob | md5
a2eae7400008e77790c3272f754a14db

Upvotes: 2

Ely
Ely

Reputation: 11152

The output is the same in your example actually. However, remove the option -n from the first example:

echo Bob | md5sum

Upvotes: 1

Related Questions