Created
January 9, 2014 10:33
-
-
Save border/8332240 to your computer and use it in GitHub Desktop.
md5 by openssl
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
gcc -std=gnu99 -o sslmd5 sslmd5.c -I/home/work/public/third-64/openssl/include -L/home/work/public/third-64/openssl/include -lcrypto |
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 <errno.h> | |
#include <limits.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include<openssl/md5.h> | |
int main(int argc, char *argv[]) | |
{ | |
if (argc < 2) { | |
fprintf(stderr, "Target required\n"); | |
return 1; | |
} | |
/* Open file and read, then call MD5 */ | |
FILE *pf = fopen(argv[1], "r"); | |
if (pf == NULL) { | |
perror("Open file: "); | |
exit(1); | |
} | |
char msg[SHRT_MAX * CHAR_MAX]; | |
size_t len = fread(msg, sizeof(char), SHRT_MAX * CHAR_MAX, pf); | |
if (errno != 0) { | |
perror("read file: "); | |
fclose(pf); | |
exit(1); | |
} | |
fclose(pf); | |
uint8_t result[16]; | |
MD5((uint8_t*) msg,len, result); | |
for (int i = 0; i < 16; i++) | |
printf("%2.2x", result[i]); | |
puts(""); | |
return EXIT_SUCCESS; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment