您的位置:首页 > 编程语言 > C语言/C++

VC++使用Crypto++库计算文件的MD5值

2013-05-23 18:19 316 查看

http://lang.9sssd.com/vcpp/art/1364

VC++使用Crypto++库计算文件的MD5值

2012-12-11 14:49 来源:博客园
作者:cxun 字号:T|T

[摘要]本文介绍VC++使用Crypto++库计算文件的MD5值,并提供简单的示例代码供参考。

VC++使用Crypto++库计算文件的MD5值代码如下:

View Row Code
#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)”。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: