Why doesn't md5 match Perl Digest :: MD5 release?

Running the md5 function from the ksh terminal does not match the output of a simple Perl script.

In the terminal, I run:

echo -n abc | md5 62fecf21103616856d72e6ffc9bcb06b 

If I ran it using Perl:

 use Digest::MD5 qw(md5_hex); foreach (@ARGV) { print "Digest is ", md5_hex($_), "\n"; } exit 

I get

 ./perl_test.sh abc Digest is 900150983cd24fb0d6963f7d28e17f72 

In all the samples I see and the md5 function sample, Perl itself looks right, but the one that uses only Ksh does not:

 md5 -x MD5 test suite: MD5 ("") = d41d8cd98f00b204e9800998ecf8427e MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661 MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72 
+4
source share
4 answers

use more portable printf

 printf "abc" | md5 
+5
source

Your echo does not recognize the -n option, so you haveh the string '-n abc \ n'.

+4
source

In addition to GregS, answer a few examples:

 $ md5 -s "-n abc"$'\012' # \012 = newline MD5 ("-n abc ") = 62fecf21103616856d72e6ffc9bcb06b 

and

 $ md5 -s "abc" MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72 
+1
source

When I run into these problems, I usually do something similar to check what my output is (e.g. showing tabs, spaces, etc.)

 $ echo abc | hexdump -c 0000000 abc \n 0000004 
0
source

Source: https://habr.com/ru/post/1301393/


All Articles