国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

C++獲取文件哈希值(hash)和獲取torrent(bt種子)磁力鏈接哈希值

2020-01-26 15:41:50
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

// 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;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄浦区| 治多县| 明星| 安塞县| 辽中县| 阳西县| 香港 | 东台市| 昌都县| 金乡县| 巢湖市| 大港区| 肥西县| 永新县| 新昌县| 长宁区| 渭源县| 容城县| 简阳市| 白河县| 嵩明县| 平山县| 嵊州市| 长岛县| 扶风县| 五河县| 新野县| 永德县| 兴隆县| 军事| 台北市| 屏东县| 南投市| 恭城| 江城| 黄石市| 临安市| 濉溪县| 平湖市| 汶上县| 临安市|