Copy Code code as follows:
Chash.h:header file
#pragma once
#include "Sha1.h"
#define Size_of_buffer 16000
Class Chash
{
Construction
Public
CString Sha1hash (CString strhashfile);
};
Copy Code code as follows:
CHash.cpp:implementation file
//
#include "stdafx.h"
#include "CHash.h"
#include <atlconv.h>
CString Chash::sha1hash (CString strhashfile)
{
Uses_conversion;
FILE *filetohash = NULL;
unsigned long lenread = 0;
unsigned char filebuf[size_of_buffer];
Sha1_ctx M_SHA1;
unsigned char* tempout = new unsigned char[256];
CString Temphash;
CString Outhash;
Sha1_begin (&M_SHA1);
Filetohash = fopen (T2A (Strhashfile), "RB");
Todo
{
Lenread = Fread (filebuf, 1, Size_of_buffer, Filetohash);
if (lenread!= 0)
{
Sha1_hash (Filebuf, Lenread, &M_SHA1);
}
while (Lenread = = Size_of_buffer);
Fclose (Filetohash); Filetohash = NULL;
Sha1_end (Tempout, &M_SHA1);
for (int i = 0; i < i++)
{
Char tmp[3];
_itoa (Tempout[i], TMP, 16);
if (strlen (tmp) = = 1)
{
TMP[1] = tmp[0];
Tmp[0] = ' 0 ';
TMP[2] = ' the ';
}
Temphash + = tmp;
}
Delete[] Tempout;
Outhash = Temphash;
return outhash;
}