07-31-2022, 02:02 AM
Thanks [Unknown]
Next question:How to calculation first 262144 byte of md5 ?
Now the full file size of md5 calc of code is:
Next question:How to calculation first 262144 byte of md5 ?
Now the full file size of md5 calc of code is:
Code:
#include "Common/Crypto/md5.h"
static char hb2hex(unsigned char hb) {
hb = hb & 0xF;
return hb < 10 ? '0' + hb : hb - 10 + 'a';
}
std::string MD5FullFile(const Path filename) {
FILE* in = File::OpenCFile(filename, "rb");
if (!in) {
WARN_LOG(COMMON, "Unable to open %s\n", filename.c_str());
return "";
}
unsigned char buff[BUFSIZ];
md5_context c;
md5_starts(&c);
unsigned char out[16];
size_t len = 0;
while ((len = std::fread(buff, sizeof(char), BUFSIZ, in)) > 0) {
md5_update(&c, buff, len);
}
md5_finish(&c, out);
std::string res;
for (size_t i = 0; i < 16; ++i) {
res.push_back(hb2hex(out[i] >> 4));
res.push_back(hb2hex(out[i]));
}
fclose(in);
return res;
}
