增加文件加解密类
This commit is contained in:
parent
65ee0774dc
commit
d873f0bf30
@ -25,6 +25,8 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
FileSenderThread.h
|
||||
FileEncryptor.h
|
||||
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET Off-line-Tools APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
|
||||
52
FileEncryptor.h
Normal file
52
FileEncryptor.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef FILEENCRYPTOR_H
|
||||
#define FILEENCRYPTOR_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QFile>
|
||||
#include <QIODevice>
|
||||
#include <QDebug>
|
||||
|
||||
class FileEncryptor {
|
||||
public:
|
||||
FileEncryptor(const QByteArray& key) : m_key(key) {}
|
||||
|
||||
// 加密或解密文件
|
||||
bool encryptDecryptFile(const QString& inputFilePath, const QString& outputFilePath) {
|
||||
// 读取文件内容
|
||||
QFile inputFile(inputFilePath);
|
||||
if (!inputFile.open(QIODevice::ReadOnly)) {
|
||||
qWarning() << "无法打开文件:" << inputFilePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray fileData = inputFile.readAll();
|
||||
inputFile.close();
|
||||
|
||||
// 对文件内容进行加解密
|
||||
xorEncryptDecrypt(fileData);
|
||||
|
||||
// 写入加解密后的文件
|
||||
QFile outputFile(outputFilePath);
|
||||
if (!outputFile.open(QIODevice::WriteOnly)) {
|
||||
qWarning() << "无法写入文件:" << outputFilePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
outputFile.write(fileData);
|
||||
outputFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
// XOR 加密/解密
|
||||
void xorEncryptDecrypt(QByteArray& data) const {
|
||||
int keyLength = m_key.size();
|
||||
for (int i = 0; i < data.size(); ++i) {
|
||||
data[i] ^= m_key[i % keyLength]; // 使用密钥与数据进行XOR操作
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray m_key; // 用于加密/解密的密钥
|
||||
};
|
||||
|
||||
#endif // FILEENCRYPTOR_H
|
||||
@ -7,6 +7,7 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QStandardItem>
|
||||
#include "FileSenderThread.h"
|
||||
#include "FileEncryptor.h"
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
|
||||
151
mainwindow.ui
151
mainwindow.ui
@ -14,27 +14,81 @@
|
||||
<string>ESP32系列脱机烧录</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>450</y>
|
||||
<width>431</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>固件选择</string>
|
||||
<string>镜像管理</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>文件:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_7">
|
||||
<property name="text">
|
||||
<string>加载</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>写入</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>10</y>
|
||||
<width>431</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>镜像生成</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>39</y>
|
||||
<width>411</width>
|
||||
<height>381</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
@ -69,49 +123,53 @@
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>镜像生成</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>文件:</string>
|
||||
<string>秘钥:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<widget class="QLineEdit" name="lineEdit_2">
|
||||
<property name="text">
|
||||
<string>加载</string>
|
||||
<string>默认使用烧录器SN作为秘钥</string>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>加密</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_6">
|
||||
<property name="text">
|
||||
<string>生成镜像</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>530</x>
|
||||
<y>20</y>
|
||||
<width>301</width>
|
||||
<height>566</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
@ -173,16 +231,6 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>/dev/tty0</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>/dev/tty1</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -294,10 +342,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user