Equivalent of md5 hashing in linux commands

2019-09-21 18:06发布

问题:

I have the following code in C

u_char buf[64] = "hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha";
//Make MD5 hash over buffer
MD5_Init(&ctx);
MD5_Update(&ctx, buf, sizeof(buf));
MD5_Final(buf, &ctx);

MD5_Init, MD5_Update and MD5_Final are from openssl library.

The above code make a MD5 hash over the buffer buf.

I want to make the same thing with linux command using md5sum

$echo -n "hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha" | md5sum

but I did not get the same result

What is the equivalent of md5 hashing in linux commands?

回答1:

Actually, md5sum is the equivalent.

echo prints out a new-line character. Try echo -n hahaha.... | md5sum.



回答2:

Do 'echo -n' rather than 'echo', echo appends a newline so you're really hashing 'hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha\n'