C++获取文件哈希值(hash)和获取torrent(bt种子)磁力链接哈希值
//CHash.h:headerfile
#pragmaonce
#include"sha1.h"
#define SIZE_OF_BUFFER 16000
classCHash
{
//Construction
public:
CStringSHA1Hash(CStringstrHashFile);
};
//CHash.cpp:implementationfile
//
#include"stdafx.h"
#include"CHash.h"
#include<atlconv.h>
CStringCHash::SHA1Hash(CStringstrHashFile)
{
USES_CONVERSION;
FILE*fileToHash=NULL;
unsignedlonglenRead=0;
unsignedcharfileBuf[SIZE_OF_BUFFER];
sha1_ctxm_sha1;
unsignedchar*tempOut=newunsignedchar[256];
CString tempHash;
CStringoutHash;
sha1_begin(&m_sha1);
fileToHash=fopen(T2A(strHashFile),"rb");
do
{
lenRead=fread(fileBuf,1,SIZE_OF_BUFFER,fileToHash);
if(lenRead!=0)
{
sha1_hash(fileBuf,lenRead,&m_sha1);
}
}while(lenRead==SIZE_OF_BUFFER);
fclose(fileToHash);fileToHash=NULL;
sha1_end(tempOut,&m_sha1);
for(inti=0;i<20;i++)
{
chartmp[3];
_itoa(tempOut[i],tmp,16);
if(strlen(tmp)==1)
{
tmp[1]=tmp[0];
tmp[0]="0";
tmp[2]="\0";
}
tempHash+=tmp;
}
delete[]tempOut;
outHash=tempHash;
returnoutHash;
}
相关文章
- C++ 特殊矩阵的压缩算法
- 学c++还是学java就业「建议收藏」
- C++多线程编程:同步之互斥量Mutex「建议收藏」
- 各种常用排序算法(C/C++,Java)动态显示
- c++ auto类型_auto C++
- C++结构体和类的区别_c++有结构体吗
- C/C++ 使用CRC检测磁盘文件完整性
- C/C++ Qt 监控文件状态变化
- 【C++ 语言】Visual Studio 配置 POSIX 线程 ( Windows 不支持 POSIX | 配置文件下载 | 库文件说明 | 配置过程 )
- 那位用Rust重写数据库的创始人来复盘了:删除27万行C++代码,值吗?
- C++类和对象(中)
- C++ winhttp 实现文件下载器
- 开心档之C++ 多线程
- C/C++/Java 程序计时功能函数详解编程语言
- C++ find_first_of(STL find_first_of)查找算法详解
- C++ upper_bound(STL upper_bound)二分查找算法详解
- C++文件读写结构体详解
- 在Linux系统下下载BT文件的技巧.(Linux下载bt)
- 如何用 C++ 读写文件
- 使用Linux命令行快速下载BT文件(linux命令行bt)
- C++字符串的反转五种方法实例
- C++用指针变量作为函数的参数接受数组的值的问题详细总结
- 深入理解c/c++内存对齐
- c++base64编解码使用示例
- C++的头文件和实现文件详解