Created
March 18, 2012 02:10
-
-
Save yukioc/2067860 to your computer and use it in GitHub Desktop.
md5 checksum of string
This file contains hidden or 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 <openssl/md5.h> | |
int main(int argc,char *argv[]){ | |
MD5_CTX c; | |
FILE *f; | |
unsigned char b[1024]; | |
unsigned char md[MD5_LBLOCK]; | |
size_t n; | |
int i; | |
if(argc!=2){ | |
printf("Usage: md5 filename\n"); | |
return 1; | |
} | |
MD5_Init(&c); | |
if((f=fopen(argv[1],"rb"))==NULL){ | |
printf("Error: file open error\n"); | |
return 1; | |
} | |
while((n=fread(b,sizeof(char),1024,f))>0){ | |
MD5_Update(&c,b,n); | |
} | |
MD5_Final(md,&c); | |
for(i=0;i<16;i++) printf("%02x",md[i]); | |
printf("\t%s\n",argv[1]); | |
fclose(f); | |
return 0; | |
} |
This file contains hidden or 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 <openssl/md5.h> | |
int main(int argc,char *argv[]){ | |
FILE *f; | |
unsigned char b[1024*1024]; | |
unsigned char md[]={ | |
0x67,0x45,0x23,0x01,0xef,0xcd,0xab,0x89, | |
0x98,0xba,0xdc,0xfe,0x10,0x32,0x54,0x76 }; | |
size_t n; | |
int i; | |
if(argc!=2){ | |
printf("Usage: md5 filename\n"); | |
return 1; | |
} | |
if((f=fopen(argv[1],"rb"))==NULL){ | |
printf("Error: file open error\n"); | |
return 1; | |
} | |
if((n=fread(b,sizeof(char),1024*1024,f))>0){ | |
MD5(b,n,md); | |
} | |
for(i=0;i<16;i++) printf("%02x",md[i]); | |
printf("\t%s\n",argv[1]); | |
fclose(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment