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;
}
相关推荐
xlp666hub18 小时前
Leetcode 第三题:用C++解决最长连续序列
c++·leetcode
会员源码网20 小时前
构造函数抛出异常:C++对象部分初始化的陷阱与应对策略
c++
xlp666hub1 天前
Leetcode第二题:用 C++ 解决字母异位词分组
c++·leetcode
不想写代码的星星1 天前
static 关键字:从 C 到 C++,一篇文章彻底搞懂它的“七十二变”
c++
xlp666hub2 天前
Leetcode第一题:用C++解决两数之和问题
c++·leetcode
不想写代码的星星2 天前
C++继承、组合、聚合:选错了是屎山,选对了是神器
c++
不想写代码的星星3 天前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
Felix_One4 天前
Qt 串口通信避坑指南:QSerialPort 的 5 个常见问题
qt
樱木Plus5 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit7 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip