当前位置:网站首页>QT base64 encryption and decryption
QT base64 encryption and decryption
2022-06-27 21:52:00 【Oriental forgetfulness】
Two encryption and decryption methods are provided here .
The first method : Use QByteArray Of toBase64 and fromBase64 To achieve .
The second method : Use base64.cpp In the document base64_encode and base64_decode To achieve . Download address
The code example is as follows :
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
QPushButton* m_encryptbtn;
QPushButton* m_decryptbtn;
QLineEdit* m_encryptedit;
QLineEdit* m_decryptedit;
};
#endif // WIDGET_H
.cpp
#include "widget.h"
#include "ui_widget.h"
#include "mycrypto.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
m_encryptbtn = new QPushButton("encrypt",this);
m_decryptbtn = new QPushButton("decrypt",this);
m_decryptedit = new QLineEdit(this);
m_encryptedit = new QLineEdit(this);
QGridLayout* lay = new QGridLayout(this);
lay->addWidget(m_encryptedit,0,0,1,1);
lay->addWidget(m_decryptedit,0,1,1,1);
lay->addWidget(m_encryptbtn,1,0,1,1);
lay->addWidget(m_decryptbtn,1,1,1,1);
this->setLayout(lay);
connect(m_encryptbtn,&QPushButton::clicked,this,[=](){
#if 0 // Method 1
m_decryptedit->setText(m_encryptedit->text().toLocal8Bit().toBase64());
#else // Method 2
m_decryptedit->setText(MyCrypto::encrypt(m_encryptedit->text().toStdString()).data());
#endif
});
connect(m_decryptbtn,&QPushButton::clicked,this,[=](){
#if 0
m_encryptedit->setText(QByteArray::fromBase64(m_decryptedit->text().toLocal8Bit()));
#else
m_encryptedit->setText(MyCrypto::decrypt(m_decryptedit->text().toStdString()).data());
#endif
});
}
Widget::~Widget()
{
delete ui;
}
.h
#ifndef MYCRYPTO_H
#define MYCRYPTO_H
#include <QString>
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <QDataStream>
class MyCrypto
{
public:
static const std::string encrypt(const std::string & orignal);
static const std::string decrypt(const std::string & orignal);
};
#endif // MYCRYPTO_H
.cpp
#include "mycrypto.h"
#include <QString>
#include <QDebug>
#include <iostream>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <string>
#include <base64.h>
using namespace std;
/**
* @brief MyCrypto::encrypt encryption
* @param orignal
* @return
*/
const std::string MyCrypto::encrypt(const std::string &orignal)
{
std::string encoded = base64_encode(reinterpret_cast<const unsigned char*>(orignal.c_str()), orignal.length());
return encoded;
}
/**
* @brief MyCrypto::decrypt Decrypt
* @param orignal
* @return
*/
const std::string MyCrypto::decrypt(const std::string &orignal)
{
std::string decoded = base64_decode(orignal);
return decoded;
}
边栏推荐
- oracle迁移mysql唯一索引大小写不区分别怕
- Go 访问GBase 8a 数据库的一个方法
- Knowledge sorting of exception handling
- 100 important knowledge points for SQL: in operator
- IO stream code
- Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
- Go from entry to practice - multiple selection and timeout control (notes)
- SQL必需掌握的100个重要知识点:检索数据
- At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
- 100 important knowledge points that SQL must master: filtering data
猜你喜欢

Go from introduction to actual combat - context and task cancellation (notes)

100 important knowledge points that SQL must master: filtering data
![[leetcode] dynamic programming solution partition array ii[arctic fox]](/img/a1/4644206db3e14c81f9f64e4da046bf.png)
[leetcode] dynamic programming solution partition array ii[arctic fox]

Codeforces Round #723 (Div. 2)

开源技术交流丨一站式全自动化运维管家ChengYing入门介绍

Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear

SQL必需掌握的100个重要知识点:使用函数处理数据

Simulink导出FMU模型文件方法

List of language weaknesses --cwe, a website worth learning

01-Golang-环境搭建
随机推荐
Go from starting to Real - Interface (note)
SQL必需掌握的100个重要知识点:排序检索数据
我想我要开始写我自己的博客了。
关于异常处理的知识整理
How to participate in openharmony code contribution
Common methods of string class
Codeforces Global Round 14
熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
集合代码练习
有时间看看ognl表达式
C语言程序设计详细版 (学习笔记1) 看完不懂,我也没办法。
Go从入门到实战——行为的定义和实现(笔记)
[LeetCode]513. 找树左下角的值
Go从入门到实战——仅执行一次(笔记)
Go从入门到实战——错误机制(笔记)
qt base64加解密
SQL必需掌握的100个重要知识点:组合 WHERE 子句
"Apprendre cette image" apparaît sur le Bureau win11 comment supprimer
SQL必需掌握的100个重要知识点:过滤数据
STM32F107+LAN8720A使用STM32cubeMX配置网络连接+tcp主从机+UDP app