不说了,直接上代码吧!注意,如果没有开启编译器优化选项,执行速度会比较慢;开启优化后,执行速度会提升好几倍。 // calculate md5 for file $p std::string CalcMD5(const boost::filesystem::path &p) { using namespace CryptoPP; MD5 md5; const size_t siz = MD5::DIGESTSIZE * 2; unsigned char buf[siz] = {0}; FileSource(p.string().c_str(), true, new HashFilter(md5, new HexEncoder(new ArraySink(buf, siz)))); return std::string(reinterpret_cast<const char*>(buf), siz); }