Skip to content

Instantly share code, notes, and snippets.

@aurelian
Created September 10, 2008 09:58
Show Gist options
  • Save aurelian/9858 to your computer and use it in GitHub Desktop.
Save aurelian/9858 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
// gcc -lssl md5.c -o md5
int main(int argc, char *argv[]) {
unsigned char buffer[1024];
int i;
unsigned char digest[16];
MD5_CTX ctx;
MD5_Init( &ctx );
switch(argc) {
// read from stdin
case 1:
while(fgets(buffer, sizeof(buffer), stdin)!=NULL) MD5_Update( &ctx, buffer, strlen(buffer)-1 );
break;
case 2:
MD5_Update( &ctx, argv[1], strlen(argv[1]) );
break;
default:
printf("Usage:\n\t%s string [or pipe]\n", argv[0]);
return -1;
}
MD5_Final(digest, &ctx);
for(i = 0; i < 16; i++) printf("%02x", digest[i]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment