3

I am using md5 algo for hashing same string in python and linux but I get different values can some one point out whats wrong

in linux: echo "logdir" | md5sum - | awk '{print $1}'

gives: aba76197efa97e6bd4e542846471b391 

in python:
md5.new("logdir".encode('utf-8')).hexdigest()

gives: ee6da4c228cfaebfda7f14e4371a097d
user1731553
  • 1,887
  • 5
  • 22
  • 33

1 Answers1

6

echo will add a newline unless you explicitly tell it not to via echo -n.

$ echo -n "logdir" | md5sum - | awk '{print $1}'
ee6da4c228cfaebfda7f14e4371a097d

From man echo:

DESCRIPTION
       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline
jDo
  • 3,962
  • 1
  • 11
  • 30