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;
}
相关推荐
Yvonne爱编码2 分钟前
二叉树高频题精讲 | 从入门到熟练掌握二叉树操作2
开发语言·python
JosieBook5 分钟前
【WinForm】C# WinForms 跨线程更新 UI 避坑指南
开发语言·ui·c#
知无不研20 分钟前
c++垃圾回收机制
开发语言·c++·智能指针·raii·垃圾回收机制
J2虾虾25 分钟前
Springboot项目中循环依赖的问题
java·开发语言
wjs202425 分钟前
C 数组:深度解析与应用场景
开发语言
lxh011327 分钟前
记忆函数题解
开发语言·javascript·ecmascript
_dindong30 分钟前
【单调栈/队列&并查集&字符串哈希&Tire树】习题集锦
数据结构·c++·算法·哈希算法
森G32 分钟前
21、信号和槽详解---------QT基础
qt
西装没钱买33 分钟前
QT组播的建立和使用(绑定特定的网卡,绑定特定IP)
网络·c++·qt·udp·udp组播
皙然1 小时前
深入理解 Java HashSet
java·开发语言