#include <stdio.h>
#include <string.h>
#include <openssl/md5.h>
bool funFileMD5SUM(char* lpcstrFilePath, char *pbymd5Buff)
{
bool bRet = false;
unsigned char achbyBuff[17] = {0};
unsigned char *pbyBuff = achbyBuff;
FILE *inFile = fopen (lpcstrFilePath, "rb");
MD5_CTX mdContext;
int bytes;
unsigned char data[1024];
if (inFile == NULL) {
printf( "%s can't be opened.\n", lpcstrFilePath);
return bRet;
}
MD5_Init (&mdContext);
while ((bytes = fread (data, 1, 1024, inFile)) != 0)
MD5_Update (&mdContext, data, bytes);
MD5_Final (pbyBuff,&mdContext);
char szBuf[1024] = {0};
for(int i = 0; i < MD5_DIGEST_LENGTH; i++)
{
sprintf(&szBuf[i*2], "%02x", pbyBuff[i]);
}
strcpy((char*)pbymd5Buff, (char*)szBuf);
strcat(szBuf, " ");
strcat(szBuf, lpcstrFilePath);
printf( "md5sum %d %s\n", MD5_DIGEST_LENGTH, szBuf);
fcl