QT C++ AES字符串加密实现

使用方法:在.h中引入类库。然后在cpp中直接引入使用即可

类库的下载地址
https://download.csdn.net/download/u012372365/88478671

具体代码:

cpp 复制代码
#include <QCoreApplication>
#include <QTest>
#ifdef __cplusplus
#include "unit_test/aestest.h"
#include "qaesencryption.h"
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QVector>
#include <QDebug>
#include <QByteArray>
#include <qbytearray.h>
#endif

QList<QString> fileList;
QList<QString> saveFileList;

//设置密钥  /替换-的目的防止字符串出现转译的情况发生
QString key("dasdlk3214k21ksd");
QString strToSeaBody(QString body){
    QString string =body;
    QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB, QAESEncryption::PKCS7);
    QByteArray enBA = encryption.encode(string.toUtf8(), key.toUtf8());
    QByteArray enBABase64 = enBA.toBase64();
    QString jieguo=enBABase64.replace("/","-");
    return jieguo;
}
QString seaToStrBody(QString str){
    str.replace("-","/").replace("\n","");
    QByteArray ba = str.toUtf8(); //方法二
    QByteArray  enBA = QByteArray::fromBase64(str.toUtf8());
    QAESEncryption encryption(QAESEncryption::AES_128, QAESEncryption::ECB, QAESEncryption::PKCS7);
    QByteArray deBA = encryption.decode(enBA, key.toUtf8());
    return QString::fromLocal8Bit( QAESEncryption::RemovePadding(deBA, QAESEncryption::PKCS7));
}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString str("sunwukong");
    QString jiami=strToSeaBody(str);
    QString jiemi=seaToStrBody(jiami);
    qDebug()<<"jiami=="<<jiami;
    qDebug()<<"jiemi=="<<jiemi;
}
相关推荐
我叫小白菜2 分钟前
【Java_EE】单例模式、阻塞队列、线程池、定时器
java·开发语言
狐凄8 分钟前
Python实例题:基于 Python 的简单聊天机器人
开发语言·python
weixin_446122461 小时前
JAVA内存区域划分
java·开发语言·redis
悦悦子a啊1 小时前
Python之--基本知识
开发语言·前端·python
QuantumStack2 小时前
【C++ 真题】P1104 生日
开发语言·c++·算法
天若有情6732 小时前
01_软件卓越之道:功能性与需求满足
c++·软件工程·软件
whoarethenext2 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
代码的奴隶(艾伦·耶格尔)3 小时前
后端快捷代码
java·开发语言
Jay_5153 小时前
C++多态与虚函数详解:从入门到精通
开发语言·c++
路来了3 小时前
Python小工具之PDF合并
开发语言·windows·python