mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-06 16:10:42 +08:00
添加哈希提取器代码
This commit is contained in:
37
others/C/hash_value_extractor/include/hash_calculator.h
Normal file
37
others/C/hash_value_extractor/include/hash_calculator.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef HASH_CALCULATOR_H
|
||||
#define HASH_CALCULATOR_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum {
|
||||
HASH_MD5,
|
||||
HASH_SHA256,
|
||||
HASH_SHA512
|
||||
} HashAlgorithm;
|
||||
|
||||
// 各算法计算函数
|
||||
int calculate_md5(const char* filename, char* output);
|
||||
int calculate_sha256(const char* filename, char* output);
|
||||
int calculate_sha512(const char* filename, char* output);
|
||||
|
||||
/**
|
||||
* 计算文件的哈希值
|
||||
* @param filename 文件路径
|
||||
* @param algorithm 哈希算法
|
||||
* @param output 输出缓冲区(必须足够大)
|
||||
* @return 成功返回0,失败返回-1
|
||||
*/
|
||||
static inline int calculate_file_hash(const char* filename, HashAlgorithm algorithm, char* output) {
|
||||
switch (algorithm) {
|
||||
case HASH_MD5:
|
||||
return calculate_md5(filename, output);
|
||||
case HASH_SHA256:
|
||||
return calculate_sha256(filename, output);
|
||||
case HASH_SHA512:
|
||||
return calculate_sha512(filename, output);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HASH_CALCULATOR_H
|
||||
21
others/C/hash_value_extractor/include/string_util.h
Normal file
21
others/C/hash_value_extractor/include/string_util.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef STRING_UTIL_H
|
||||
#define STRING_UTIL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// 快速分配字符串内存
|
||||
char* str_alloc(size_t size);
|
||||
|
||||
// 快速释放字符串内存
|
||||
void str_free(char* str);
|
||||
|
||||
// 快速字符串复制
|
||||
char* str_copy(const char* src);
|
||||
|
||||
// 快速字符串连接
|
||||
char* str_concat(const char* str1, const char* str2);
|
||||
|
||||
// 二进制转十六进制字符串
|
||||
char* bin_to_hex(const unsigned char* data, size_t len);
|
||||
|
||||
#endif // STRING_UTIL_H
|
||||
Reference in New Issue
Block a user