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;
}
相关推荐
沐怡旸30 分钟前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥1 小时前
C++ 内存管理
c++
博笙困了7 小时前
AcWing学习——双指针算法
c++·算法
感哥8 小时前
C++ 指针和引用
c++
感哥18 小时前
C++ 多态
c++
沐怡旸1 天前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River4161 天前
Javer 学 c++(十三):引用篇
c++·后端
感哥1 天前
C++ std::set
c++
侃侃_天下1 天前
最终的信号类
开发语言·c++·算法
博笙困了1 天前
AcWing学习——差分
c++·算法