Skip to content

Instantly share code, notes, and snippets.

@itszero
Created April 22, 2009 16:40
Show Gist options
  • Save itszero/99900 to your computer and use it in GitHub Desktop.
Save itszero/99900 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstdlib>
using namespace std;
char* md5(char* str)
{
char cmd[500];
sprintf(cmd, "echo -n \"%s\" | md5sum", str);
FILE *fd = popen(cmd, "r");
char *hash = (char*)malloc(sizeof(char) * 33);
hash[32] = NULL;
fread(hash, sizeof(char), 32, fd);
pclose(fd);
return hash;
}
int main()
{
printf("MD5 of HelloWorld: %s\n", md5("HelloWorld"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment