当前位置: 首页 > news >正文

QT C++ AES字符串加密实现

使用方法:在.h中引入类库。然后在cpp中直接引入使用即可
类库的下载地址
https://download.csdn.net/download/u012372365/88478671
具体代码:
 

#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>
#endifQList<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;
}

http://www.lryc.cn/news/211945.html

相关文章:

  • 关于mysql json字段创建索引
  • “探索Linux世界:从CentOS安装到常见命令使用“
  • SVN出现Cleanup failed to process the following paths...
  • gitee上传项目
  • 实现文件上传和下载
  • 大数据-Storm流式框架(七)---Storm事务
  • Kafka - 3.x Kafka消费者不完全指北
  • Gerrit | 重磅! 2.x 版本升级到 3.x 版本----转
  • 使用c++编程语言,用递归的方法求第n个斐波那契数,代码如下
  • git config pull.rebase false
  • Spring面试题:(一)IoC,DI,AOP和BeanFactory,ApplicationContext
  • RabbitMQ如何保证消息不丢失呢?
  • VR步进式漫游,轻松构建三维模型,带来展示新形式!
  • 英语——分享篇——常用人物身份
  • 202310-宏基组学物种分析工具-MetaPhlAn4安装和使用方法-Anaconda3- centos9 stream
  • systrace/perfetto如何看surfaceflinger的vsync信号方法-android framework实战车载手机系统开发
  • 一文带你彻底弄懂js事件循环(Event Loop)
  • 数据结构与算法:二叉树之“堆排序”
  • gma 2 教程(三)坐标参考系统:2.基准面/椭球体
  • 【1day】复现广联达-Linkworks 协同办公管理平台信息泄露漏洞
  • Spring Cloud之ElasticSearch的学习【详细】
  • vscode免密码认证ssh连接virtual box虚拟机
  • 【Linux】Centos yum源替换
  • uniapp组件初始化的销毁(监听隐藏事件)
  • leetcode:1207. 独一无二的出现次数(python3解法)
  • 2023秋《论文写作》课程总结
  • Linux学习第27天:Platform设备驱动开发: 专注与分散
  • 最长公共子序列
  • 万字解析设计模式之工厂方法模式与简单工厂模式
  • One-to-N N-to-One: Two Advanced Backdoor Attacks Against Deep Learning Models