当前位置: 首页 > 工具软件 > CSHA1 > 使用案例 >

使用开源代码CSHA1 - A,计算文件和字符串SHA1

越勇锐
2023-12-01

使用开源代码,计算文件和字符串SHA1
开源项目:
http://www.codeproject.com/Articles/2463/CSHA1-A-C-Class-Implementation-of-the-SHA-1-Hash-A

void GetSHA()
{
    int iIndex = -1;
    CSHA1 sha1;
    do 
    {
        printf("输入数字选择想校验SHA1的类型:\nFile is 1 \nString is 2 \nExit is 3 \r\n");
        scanf("%d",&iIndex);
        if (iIndex == 1)
        {
            TCHAR str[] = {0};
            printf("请输入文件名全路径或者直接拖到DOS窗口\n");
            scanf("%s",str);
            sha1.HashFile(str);
            sha1.Final();
            TCHAR tszReport[41]; 
            sha1.ReportHash(tszReport, CSHA1::REPORT_HEX_SHORT);
            _tprintf(_T("\r\n File hashed to:\r\n "));
            _tprintf(tszReport); 
            _tprintf(_T("\n"));
        }
        if (iIndex == 2)
        {
            char chTemp[128] = {0};
            printf("请输入字符串\r\n");
            scanf("%s",chTemp);
            sha1.Update(reinterpret_cast<const unsigned char*>(chTemp), strlen(chTemp));
            sha1.Final();
            std::basic_string<TCHAR> strReport;
            sha1.ReportHashStl(strReport, CSHA1::REPORT_HEX_SHORT);
            _tprintf(_T("\r\n String hashed to:\r\n "));
            _tprintf(strReport.c_str());
            _tprintf(_T("\r\n"));
//          std::cout<<"Hash is :["<<hex<<strReport.c_str()<<"]"<<endl;

        }
        sha1.Reset();
    } while (iIndex != 3);
}
 类似资料: