C++获取文件哈希值(hash)和获取torrent(bt种子)磁力链接哈希值
// CHash.h : header file
#pragma once
#include "sha1.h"#define SIZE_OF_BUFFER 16000
class CHash
{
// Construction
public:
CString SHA1Hash(CString strHashFile);
};
// CHash.cpp : implementation file
//
#include "stdafx.h"
#include "CHash.h"
#include <atlconv.h>CString CHash::SHA1Hash(CString strHashFile)
{
USES_CONVERSION;
FILE *fileToHash = NULL;
unsigned long lenRead = 0;
unsigned char fileBuf[SIZE_OF_BUFFER];
sha1_ctx m_sha1;
unsigned char* tempOut = new unsigned char[256];
CString tempHash;
CString outHash;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 (int i = 0 ; i < 20 ; i++)
{
char tmp[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;
return outHash;
}
您可能感兴趣的文章:
- C/C++获取当前时间
- c++代码通过JNI调用Java代码时用到的签名信息如何获取
- C++程序中获取不带文件路径和后缀的文件名
- windows平台下 c++获取 系统版本 网卡 内存 CPU 硬盘 显卡信息<转>
- c++中关于hash_map自定义equal function和hash function
- C/C++中如何获取数组的长度
- 海康威视NVR获取网络摄像头报警信息 C++ 实现
- C++ 获取指定文件夹下指定后缀名文件
- C/C++获取shell命令返回值
- c++ 中 毫秒级时间获取
- c++ 读取stdin 获取标准输出内容
- c++获取windows时间的方法(转)
- C/C++&nbsp;中如何获取数组长度
- C/C++获取当前系统时间
- C/C++中手动获取调用堆栈【转】
- C/C++获取当前时刻的时分秒
- C++获取屏幕输入
- c++ 使用管道获取CMD命令结果
- [转载] C/C++中怎样获取日期和时间
- C++获取汉字拼音首字母(转)