环境:Qt5.9.7,vs2015,MSVC2015 32bit,cryptopp820.zip
1、下载crypto++源码 https://www.cryptopp.com/release820.html并解压到cryptopp文件夹。
2、vs2015打开cryptopp目录下 cryptest.sln工程文件,有4个项目
3、设置编译输出为Release(或Debug),四个项目分别右键——>属性——>C/C++——>代码生成——>运行库,改成动态库多线程MD(或者动态库多线程调试MTD),然后在cryptest项目上右键——>生成,等待完成。
4、在cryptopp目录下会新增编译目录,动态库文件在cryptopp/Win32/Output/Release( 或Debug)目录下
5、QT新建一个工程,在工程目录下新增目录c++/cryptopp/lib,c++/cryptopp/include, 将cryptlib.lib添加到../cryptopp/lib目录下,将cryptopp目录下的所有.h文件复制到../cryptopp/include目录下,在 Pro中添加头引用和库引用如下:
INCLUDEPATH += "$$PWD/c++/cryptopp/include"
LIBS += -L"$$PWD/c++/cryptopp/lib" -lcryptlib
6、在c++文件中添加测试代码:
//引用头文件
#include "c++/cryptopp/include/md5.h"
#include "c++/cryptopp/include/filters.h"
#include "c++/cryptopp/include/hex.h"
//测试主要代码
std::string text="abc123";
std::string digest;
CryptoPP::Weak1::MD5 md5;
CryptoPP::HashFilter hashfilter(md5);
hashfilter.Attach(new CryptoPP::HexEncoder(new CryptoPP::StringSink(digest), false));
hashfilter.Put(reinterpret_cast<const unsigned char*>(text.c_str()), text.length());
hashfilter.MessageEnd();
QString tmp= QString::fromStdString(digest);
qDebug()<<"md5:"<<tmp;