1 Star 0 Fork 28

赵天宇/文件软硬件加解密平台

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AESwidget.cpp 3.79 KB
一键复制 编辑 原始数据 按行查看 历史
qingfengfumeng 提交于 2024-09-13 15:38 . update AESwidget.cpp.
#include "AESwidget.h"
#include "ui_AESwidget.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QFile>
AESwidget::AESwidget(QWidget *parent):
QWidget(parent),
ui(new Ui::AESwidget)
{
ui->setupUi(this);
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8") // 解决中文乱码问题
#endif
ui->progressBar->setRange(0, 100); // 设置进度条的范围从0到100
ui->progressBar->setValue(0); // 初始化进度条的值为0
//设置信号
connect(ui->genpushButton, SIGNAL(clicked()), this, SLOT(genpushButton_click()));
connect(ui->filepushButton, SIGNAL(clicked()), this, SLOT(filepushButton_click()));
connect(ui->keypushButton, SIGNAL(clicked()), this, SLOT(keypushButton_click()));
connect(ui->encryptpushButton, SIGNAL(clicked()), this, SLOT(encryptpushButton_click()));
connect(ui->decryptpushButton, SIGNAL(clicked()), this, SLOT(decryptpushButton_click()));
connect(ui->backpushButton, SIGNAL(clicked()), this, SLOT(backpushButton_click()));
}
AESwidget::~AESwidget()
{
delete ui;
}
void AESwidget::on_genpushButton_clicked()
{
QString folderPath = QFileDialog::getExistingDirectory(this, "Select Folder", QDir::homePath());
if (!folderPath.isEmpty())
{
QString fileName = folderPath + "/key.txt";
QFile file(fileName);
std::string filePathStr = fileName.toStdString();
aes.genKey(filePathStr);
// 更新进度条的值
ui->progressBar->setValue(100);
QMessageBox::information(this, "Success", "密钥生成成功!");
ui->textBrowser->append("生成的密钥存储在: " + fileName);
}
}
void AESwidget::on_filepushButton_clicked()
{
QString filePath = QFileDialog::getOpenFileName(this, "Open File", QDir::homePath(), "Text files (*.txt)");
if (!filePath.isEmpty())
{
ui->progressBar->setValue(0);
infile_path = filePath.toStdString();
ui->filelineEdit->setText(filePath);
ui->textBrowser->append("选择文件: " + filePath);
}
}
void AESwidget::on_keypushButton_clicked()
{
QString filePath = QFileDialog::getOpenFileName(this, "Open File", QDir::homePath(), "Text files (*.txt)");
if (!filePath.isEmpty())
{
ui->progressBar->setValue(0);
key_path = filePath.toStdString();
ui->keylineEdit->setText(filePath);
aes.getKey(key_path);
ui->textBrowser->append("密钥文件: " + filePath);
}
}
void AESwidget::on_encryptpushButton_clicked()
{
QString folderPath = QFileDialog::getExistingDirectory(this, "Select Folder", QDir::homePath());
if (!folderPath.isEmpty())
{
QString fileName = folderPath + "/encrypted_file.txt";
QFile file(fileName);
std::string outfile_path = fileName.toStdString();
aes.encrypt_file(infile_path, outfile_path);
ui->progressBar->setValue(100);
QMessageBox::information(this, "Success", "文件加密成功!");
ui->textBrowser->append("加密后的文件存放路径: " + fileName);
}
}
void AESwidget::on_decryptpushButton_clicked()
{
QString folderPath = QFileDialog::getExistingDirectory(this, "Select Folder", QDir::homePath());
if (!folderPath.isEmpty())
{
QString fileName = folderPath + "/decrypted_file.txt";
QFile file(fileName);
std::string outfile_path = fileName.toStdString();
aes.decrypt_file(infile_path, outfile_path);
ui->progressBar->setValue(100);
QMessageBox::information(this, "Success", "文件解密成功!");
ui->textBrowser->append("解密后的文件存放路径: " + fileName);
}
}
void AESwidget::on_backpushButton_clicked()
{
emit sendsignal();
this->close();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zty1027/cryptography_file_protection.git
git@gitee.com:zty1027/cryptography_file_protection.git
zty1027
cryptography_file_protection
文件软硬件加解密平台
master

搜索帮助