续上述博客
跳转到移植视频-blibili
<iframe allowfullscreen="true" data-mediaembed="bilibili" id="wXDEsbKp-1634515414322" src="https://player.bilibili.com/player.html?aid=208570859"></iframe>C语言计算小文件MD5
修改后的md5test.cpp代码如下:
#include <iostream> #include "md5/md5.h" int main() { FILE* Fp = nullptr; fopen_s(&Fp, "d:\\test.zip", "rb"); if (Fp) { fseek(Fp, 0, SEEK_END); int FileSize = ftell(Fp); fseek(Fp, 0, SEEK_SET); unsigned char* Data = (unsigned char*)malloc(FileSize); memset(Data, 0, FileSize); fread(Data, 1, FileSize, Fp); unsigned char md[MD5_DIGEST_LENGTH] = { 0 }; unsigned char* P = MD5(Data, FileSize, md); free(Data); for (int i = 0; i < MD5_DIGEST_LENGTH; i++) { printf("%02x-", *(md + i)); } fclose(Fp); } }
输出结果:
d0-3e-c4-cb-b5-ef-82-87-c5-a0-17-69-59-54-74-69-
使用md5校验软件计算的结果:
完全一致
欢迎大家关注、留言讨论、可分享源码