对于从文件路径名生成 Hask Key 的哈希函数有什么想法吗?我想用它来维护每个文件的信息,因为每个文件的路径都是唯一的,即使它们具有相同的文件名!
最佳答案
你可以使用openssl哈希函数,这只是一个例子:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
int main()
{
int i;
unsigned char result[MD5_DIGEST_LENGTH];
const char *string = "path/to/file";
MD5(string, strlen(string), result);
// output
for(i = 0; i < MD5_DIGEST_LENGTH; i++)
printf("%02x", result[i]);
printf("\n");
return EXIT_SUCCESS;
}
关于linux - 哈希函数从文件路径生成哈希键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13660348/