???C???????MD5?,?????????:
1. ????????:
```c
#include
#include
#include
#include
```
2. ????????????MD5?:
```c
void compute_md5(const char* filepath, unsigned char* md5_hash) {
FILE* file = fopen(filepath, "rb");
if(file == NULL) {
printf("??????\n");
return;
}
MD5_CTX md5_ctx;
MD5_Init(&md5_ctx);
unsigned char buffer[1024];
int bytes;
while((bytes = fread(buffer, 1, sizeof(buffer), file)) != 0) {
MD5_Update(&md5_ctx, buffer, bytes);
}
MD5_Final(md5_hash, &md5_ctx);
fclose(file);
}
```
3. ???????compute_md5????????MD5?:
```c
int main() {
const char* filepath = "????";
unsigned char md5_hash[MD5_DIGEST_LENGTH];
compute_md5(filepath, md5_hash);
// ?MD5??16????????
for(int i = 0; i < MD5_DIGEST_LENGTH; i++) {
printf("x", md5_hash[i]);
}
printf("\n");
return 0;
}
```
???,?????????OpenSSL????,??????????:
```bash
gcc -o ??? ????.c -lcrypto
```
??"????"???????MD5??????????