Equivalent of md5 hashing in linux commands

本小妞迷上赌 提交于 2019-12-13 10:42:11

问题


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'



来源:https://stackoverflow.com/questions/16446306/equivalent-of-md5-hashing-in-linux-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!