|
|
@ -20,16 +20,16 @@ string Checksum::checksum_of_file(const string& filepath, checksum_algorithms al |
|
|
|
// cout << "processing file '" << filepath << "'" << endl;
|
|
|
|
if (file.is_open() ) { |
|
|
|
ifstream::pos_type fileSize; |
|
|
|
char * memBlock; |
|
|
|
unsigned char * memBlock; |
|
|
|
fileSize = file.tellg(); |
|
|
|
memBlock = new char[fileSize]; |
|
|
|
memBlock = new unsigned char[fileSize]; |
|
|
|
if (nullptr != memBlock) { |
|
|
|
file.seekg(0,ios::beg); |
|
|
|
file.read(memBlock, fileSize); |
|
|
|
file.read(reinterpret_cast<char*>(memBlock), fileSize); |
|
|
|
switch ( alg ) { |
|
|
|
case md5: { |
|
|
|
unsigned char result[MD5_DIGEST_LENGTH]; |
|
|
|
MD5(reinterpret_cast<unsigned char*>( memBlock), fileSize, result); |
|
|
|
MD5(memBlock, fileSize, result); |
|
|
|
for (unsigned char i : result) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i); |
|
|
|
} |
|
|
@ -37,7 +37,7 @@ string Checksum::checksum_of_file(const string& filepath, checksum_algorithms al |
|
|
|
} |
|
|
|
case sha1: { |
|
|
|
unsigned char result[SHA_DIGEST_LENGTH]; |
|
|
|
SHA1(reinterpret_cast<unsigned char*>( memBlock), fileSize, result); |
|
|
|
SHA1(memBlock, fileSize, result); |
|
|
|
for (unsigned char i : result) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i); |
|
|
|
} |
|
|
@ -45,7 +45,7 @@ string Checksum::checksum_of_file(const string& filepath, checksum_algorithms al |
|
|
|
} |
|
|
|
case sha256: { |
|
|
|
unsigned char result[SHA_DIGEST_LENGTH]; |
|
|
|
SHA256(reinterpret_cast<unsigned char*>( memBlock), fileSize, result); |
|
|
|
SHA256( memBlock, fileSize, result); |
|
|
|
for (unsigned char i : result) { |
|
|
|
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i); |
|
|
|
} |
|
|
|