c++进行文件摘要

以前写过一篇文章介绍怎么取得字符串的md5值。现在补充一下文件的,也是一个道理:
AnsiString fn(filename);

    char p[20] = {0};  //内存
    char p1[41] = {0}; //16进制  注意41位

    CSHA1 sha1;
    sha1.HashFile(fn.c_str()); // Hash in the contents of the file
                                  // 'TheFile.cpp'
    sha1.Final();

    //sha1.ReportHash(szReport, CSHA1::REPORT_HEX); // Get final hash as
                                                  // pre-formatted string
    // or
    sha1.GetHash(p); // Get the raw message digest bytes to a
                               // temporary buffer

    BinToHex(p,p1,20);

    wsResult = WideString(p1);

注意BinToHex(p,p1,20);

你可能感兴趣的:(blog)