Skip to content

Instantly share code, notes, and snippets.

@border
Created January 9, 2014 10:33
Show Gist options
  • Save border/8332240 to your computer and use it in GitHub Desktop.
Save border/8332240 to your computer and use it in GitHub Desktop.
md5 by openssl
gcc -std=gnu99 -o sslmd5 sslmd5.c -I/home/work/public/third-64/openssl/include -L/home/work/public/third-64/openssl/include -lcrypto
#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