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;
}
相关推荐
2601_966949651 分钟前
Python 实战:如何统计五档盘口买卖盘总挂单量?附计算公式与代码
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
全栈陈序员30 分钟前
【Python】基础语法入门(二十九)—— 正则表达式实战:文本处理利器
开发语言·人工智能·python·正则表达式
Wang's Blog37 分钟前
Java 项目实战: 交友项目 - 发布评论
java·开发语言·交友
屈冠成37 分钟前
ShopXO商城系统测试报告
开发语言·spring·maven·lua
多弗朗皮卡丘44 分钟前
C++STL之空间配置器
开发语言·c++·内存池·空间配置器
tommyjiatong1 小时前
什么是PHP漏洞
开发语言·php
牵猫散步的鱼儿1 小时前
Demosaic 和 Remosaic
c++
CodeYp20191 小时前
第19讲:封装红黑树实现 mymap 和 myset
开发语言·c++·红黑树
Quz1 小时前
QML 字体度量与文本度量:FontMetrics 与 TextMetrics
qt
Quz1 小时前
QML 字体加载:FontLoader 与 FontInfo
qt