Created
September 10, 2008 09:58
-
-
Save aurelian/9858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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