1、下载Crypto++ v5.6.4,并解压;
https://codeload.github.com/weidai11/cryptopp/zip/CRYPTOPP_5_6_4
2、新建文件 cryptopp564 ,把解压后的文件全部复制进去,不要子文件夹路径;
3、随便复制一个其它项目的.pro到当前目录下,粘贴后,将这个文件重命名为 CryptoPPLib.pro 编辑器打开,内容清空,粘贴以下内容;
CryptoPPLib.pro文件内容如下:
QT -= core gui
TARGET = CryptoPPLib
TEMPLATE = lib
DEFINES += CRYPTOPPLIB_LIBRARY
SOURCES += \
3way.cpp \
adler32.cpp \
algebra.cpp \
algparam.cpp \
arc4.cpp \
asn.cpp \
authenc.cpp \
base32.cpp \
base64.cpp \
basecode.cpp \
bfinit.cpp \
blowfish.cpp \
blumshub.cpp \
camellia.cpp \
cast.cpp \
casts.cpp \
cbcmac.cpp \
ccm.cpp \
channels.cpp \
cmac.cpp \
cpu.cpp \
crc.cpp \
cryptlib.cpp \
default.cpp \
des.cpp \
dessp.cpp \
dh.cpp \
dh2.cpp \
dll.cpp \
dsa.cpp \
eax.cpp \
ec2n.cpp \
eccrypto.cpp \
ecp.cpp \
elgamal.cpp \
emsa2.cpp \
eprecomp.cpp \
esign.cpp \
files.cpp \
filters.cpp \
fips140.cpp \
gcm.cpp \
gf2_32.cpp \
gf2n.cpp \
gf256.cpp \
gfpcrypt.cpp \
gost.cpp \
gzip.cpp \
hex.cpp \
hmac.cpp \
hrtimer.cpp \
ida.cpp \
idea.cpp \
integer.cpp \
iterhash.cpp \
luc.cpp \
mars.cpp \
marss.cpp \
md2.cpp \
md4.cpp \
md5.cpp \
misc.cpp \
modes.cpp \
mqueue.cpp \
mqv.cpp \
nbtheory.cpp \
network.cpp \
oaep.cpp \
osrng.cpp \
panama.cpp \
pch.cpp \
pkcspad.cpp \
polynomi.cpp \
pssr.cpp \
pubkey.cpp \
queue.cpp \
rabin.cpp \
randpool.cpp \
rc2.cpp \
rc5.cpp \
rc6.cpp \
rdtables.cpp \
rijndael.cpp \
ripemd.cpp \
rng.cpp \
rsa.cpp \
rw.cpp \
safer.cpp \
salsa.cpp \
seal.cpp \
seed.cpp \
serpent.cpp \
sha.cpp \
sha3.cpp \
shacal2.cpp \
shark.cpp \
sharkbox.cpp \
simple.cpp \
skipjack.cpp \
socketft.cpp \
sosemanuk.cpp \
square.cpp \
squaretb.cpp \
strciphr.cpp \
tea.cpp \
tftables.cpp \
tiger.cpp \
tigertab.cpp \
trdlocal.cpp \
ttmac.cpp \
twofish.cpp \
vmac.cpp \
wait.cpp \
wake.cpp \
whrlpool.cpp \
winpipes.cpp \
xtr.cpp \
xtrcrypt.cpp \
zdeflate.cpp \
zinflate.cpp \
zlib.cpp
HEADERS += \
3way.h \
adler32.h \
aes.h \
algebra.h \
algparam.h \
arc4.h \
argnames.h \
asn.h \
authenc.h \
base32.h \
base64.h \
basecode.h \
# bench \
blake2.h \
blowfish.h \
blumshub.h \
camellia.h \
cast.h \
cbcmac.h \
ccm.h \
chacha.h \
channels.h \
cmac.h \
config.h \
cpu.h \
crc.h \
cryptlib.h \
default.h \
des.h \
dh.h \
dh2.h \
dll.h \
dmac.h \
dsa.h \
eax.h \
ec2n.h \
eccrypto.h \
ecp.h \
elgamal.h \
emsa2.h \
eprecomp.h \
esign.h \
factory.h \
fhmqv.h \
files.h \
filters.h \
fips140.h \
fltrimpl.h \
gcm.h \
gf2_32.h \
gf2n.h \
gf256.h \
gfpcrypt.h \
gost.h \
gzip.h \
hex.h \
hkdf.h \
hmac.h \
hmqv.h \
hrtimer.h \
ida.h \
idea.h \
integer.h \
iterhash.h \
keccak.h \
lubyrack.h \
luc.h \
mars.h \
md2.h \
md4.h \
md5.h \
mdc.h \
mersenne.h \
misc.h \
modarith.h \
modes.h \
modexppc.h \
mqueue.h \
mqv.h \
nbtheory.h \
network.h \
nr.h \
oaep.h \
oids.h \
osrng.h \
ossig.h \
panama.h \
pch.h \
pkcspad.h \
polynomi.h \
pssr.h \
pubkey.h \
pwdbased.h \
queue.h \
rabin.h \
randpool.h \
rc2.h \
rc5.h \
rc6.h \
rdrand.h \
resource.h \
rijndael.h \
ripemd.h \
rng.h \
rsa.h \
rw.h \
safer.h \
salsa.h \
seal.h \
secblock.h \
seckey.h \
seed.h \
serpent.h \
serpentp.h \
sha.h \
sha3.h \
shacal2.h \
shark.h \
simple.h \
skipjack.h \
smartptr.h \
socketft.h \
sosemanuk.h \
square.h \
stdcpp.h \
strciphr.h \
tea.h \
tiger.h \
trap.h \
trdlocal.h \
trunhash.h \
ttmac.h \
twofish.h \
# validate.h \
vmac.h \
wait.h \
wake.h \
whrlpool.h \
winpipes.h \
words.h \
xtr.h \
xtrcrypt.h \
zdeflate.h \
zinflate.h \
zlib.h \
unix {
target.path = /usr/lib
INSTALLS += target
}
# added manually
LIBS += -lws2_32
CONFIG += warn_off
4、删除当前目录下 GNUmakefile 此文件;
5、编译库lib
5. 1、 用QTCreator打开CryptoPPLib.pro;
5. 2、取消,shadow build勾选;
5.3、执行qmake
5.4、点击最下放构建,钉锤标志(这是生成lib,不需要执行 run)即可。
5.5、点击箭头处切换到release,继续执行1-4步。
5.6、最终会生成,debug和release两个文件里,各有一个.a和一个.dll,如下图;
至此,基于Crypto++的lib编译完成。
二.测试QT调用;
1、新建一个qt项目;
2、main目录下新建文件夹cryptopp;
3、在cryptopp文件夹里,新建 Include 和 Lib 共两个子文件夹;
4、将原cryptopp564文件夹下所有头文件(.h)文件复制到 Include文件夹;
5、将原来5.6的debug和release文件,复制到Lib文件夹里;
将以下内容追加到,当前测试项目,.pro文件结尾;
CONFIG += warn_off
LIBS += -lws2_32
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/release/ -lCryptoPPLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/cryptopp/Lib/debug/ -lCryptoPPLib
else:unix: LIBS += -L$$PWD/ -lCryptoPPLib
DEPENDPATH += $$PWD/
INCLUDEPATH+=$$PWD/cryptopp/Include
6、包含头文件,调用,测试,如下:
#include <QCoreApplication>
#include <qdebug.h>
#include <iostream>
#define CRYPTOPP_DEFAULT_NO_DLL
#include <dll.h>
#ifdef CRYPTOPP_WIN32_AVAILABLE
#include <windows.h>
#endif
#include "base32.h"
#include "base64.h"
#include <filters.h>
using namespace CryptoPP;
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
string src="让世界爱上中国造!";
string dst;
StringSource(src, true, new Base64Encoder(new StringSink(dst)));
qDebug()<<"encode src="<<src.c_str()<<endl;
cout<<"encode dst="<<dst<<endl;
string src2="6K6p5LiW55WM54ix5LiK5Lit5Zu96YCg77yB";
string dst2;
StringSource(src2, true, new Base64Decoder(new StringSink(dst2)));
cout<<"decode src2="<<src2<<endl;
qDebug()<<"decode dst2="<<dst2.c_str()<<endl;
return a.exec();
}
结果如下: base64编码 base64解码
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之家整理,本文链接:https://www.bmabk.com/index.php/post/96513.html