Code:
#include <iostream>
#include <iomanip>
#include <openssl/md5.h>
int main()
{
unsigned char buffer[16];
unsigned char input = '\0';
/* first argument needs to be an unsigned char pointer
* second argument is number of bytes in the first argument
* last argument is our buffer, which needs to be able to hold
* the 16 byte result of the MD5 operation */
MD5(&input, 1, buffer);
/* the result in buffer is not a string as you seem to expect,
* it's a sequence of bytes. you can print it like so:
*/
for(int i = 0; i < sizeof(buffer); ++i) {
std::cout << std::hex /* print numbers as hexadecimal */
<< std::setw(2) /* print two digits */
<< std::setfill('0') /* pad with '0' */
<< static_cast<int>(buffer[i]);
}
std::cout << std::endl;
/* compare the output to: echo -e -n '\0' | md5sum */
return 0;
}
You need to link with -lssl
Bookmarks