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;
}
相关推荐
应用市场36 分钟前
构建自定义命令行工具 - 打造专属指令体
开发语言·windows·python
FFZero11 小时前
【C++/Lua联合开发】 (二) Lua调用C++函数
c++·junit·lua
Dfreedom.1 小时前
一文掌握Python四大核心数据结构:变量、结构体、类与枚举
开发语言·数据结构·python·变量·数据类型
一半烟火以谋生1 小时前
Python + Pytest + Allure 自动化测试报告教程
开发语言·python·pytest
虚行1 小时前
C#上位机工程师技能清单文档
开发语言·c#
小羊在睡觉2 小时前
golang定时器
开发语言·后端·golang
CoderCodingNo2 小时前
【GESP】C++四级真题 luogu-B4068 [GESP202412 四级] Recamán
开发语言·c++·算法
一个不知名程序员www2 小时前
算法学习入门---双指针(C++)
c++·算法
Maple_land2 小时前
常见Linux环境变量深度解析
linux·运维·服务器·c++·centos
Larry_Yanan3 小时前
QML学习笔记(四十四)QML与C++交互:对QML对象设置objectName
开发语言·c++·笔记·qt·学习·ui·交互