openssl库md5源码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
#define MAX_DATA_LEN 1024
#define MD5_LENTH 16
int main(int argc, char **argv)
{
MD5_CTX md5_ctx;
FILE *fp = NULL;
char *strFilePath = argv[1];
unsigned char MD5result[MD5_LENTH];
char DataBuff[MAX_DATA_LEN];
int len;
int t = 0;
int i;
fp = fopen(strFilePath, "rb");
do
{
MD5_Init(&md5_ctx);
while(!feof(fp))
{
memset(DataBuff, 0x00, sizeof(DataBuff));
len = fread(DataBuff, 1, MAX_DATA_LEN, fp);
if(len)
{
t += len;
MD5_Update(&md5_ctx, DataBuff, len);
}
}
MD5_Final(MD5result,&md5_ctx);
puts("file MD5:");
for(i = 0; i<MD5_LENTH; i++)
{
printf("%02x", (int)MD5result[i]);
}
puts("\n");
} while(0);
fclose(fp);
MD5((const unsigned char*)strFilePath, strlen(strFilePath), MD5result);
puts("string MD5:");
for(i = 0; i < MD5_LENTH; i++)
{
printf("%02x", (int)MD5result[i]);
}
puts("\n");
return 0;
}