此文参考:《应用Crypto++计算文件的MD5校验和》

直接上代码:

#include <iostream>
using namespace std;

#include "md5.h"
#include "hex.h"
#include "files.h"
#pragma comment(lib, "cryptlib.lib")

void main()
{
	CryptoPP::Weak1::MD5 md;
	const size_t size = CryptoPP::Weak1::MD5::DIGESTSIZE * 2;
	byte buf[size] = {0};
	string strPath = "d:\\a.dat";
	CryptoPP::FileSource(strPath.c_str(), true,
		new CryptoPP::HashFilter(md,
		new CryptoPP::HexEncoder(
		new CryptoPP::ArraySink(buf, size))));
	string strHash = string(reinterpret_cast<const char*>(buf), size);
	std::cout<<strHash.c_str()<<endl;
}

  在Visual Studio中设置编译器优化代码后,执行速度会比较高,经测试,要比一般的Hash软件还快一点。设置方法如下:

Project Properties -> Configuration Properties -> C/C++ -> Optimization -> Optimization中,选择为“Maximize Speed (/O2)”

相关文章:

  • 2021-07-06
  • 2021-10-08
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2023-04-08
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
相关资源
相似解决方案