#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "EncipherMent.h"
#include <QApplication>
#include <QFile>
#include <fstream>
#include "openssl/rsa.h"
#define KEY_LENGTH 2048 // 密钥长度
#define PUB_KEY_FILE "pubkey.pem" // 公钥路径
#define PRI_KEY_FILE "prikey.pem" // 私钥路径
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString strClear = "--------------------begin------------------------\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
"helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt helloworld public key encrypt, private key decrypt\n"
" --------------9527------------------\n";
// std::string pub_key;
// std::string pri_key;
// //GenerateRSAKey(pub_key, pri_key);
// qDebug() << pub_key.c_str();
// qDebug() << pri_key.c_str();
// std::string encrypt_text;
// std::string decrypt_text;
// // 公钥加密-私钥解密
// encrypt_text = RsaPubEncrypt(strClear.toStdString(), strPubKey.toStdString());
// qDebug() << encrypt_text.c_str();
// decrypt_text = RsaPriDecrypt(encrypt_text, strPriKey.toStdString());
// qDebug() << decrypt_text.c_str();
QString encryptedFilePath = "C:\\Users\\Administrator\\Desktop\\src\\asd.txt";
// 加密并将数据写入文件
encryptAndWriteToFile(strClear, encryptedFilePath);
// 从文件中读取并解密数据
QString decryptedText = readAndDecryptFromFile(encryptedFilePath);
qDebug() << "Decrypted text:" << decryptedText;
}
QString MainWindow::readKeyFromFile(const QString& filePath) {
QString keyData;
QFile keyFile(filePath);
if (keyFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream inStream(&keyFile);
keyData = inStream.readAll();
keyFile.close();
} else {
qDebug() << "Error: Unable to open key file for reading.";
}
return keyData;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::encryptAndWriteToFile(const QString& clearText, const QString& outputFilePath) {
// 加密明文数据
std::string encryptText = RsaPubEncrypt(clearText.toStdString(), strPubKey.toStdString());
// 将加密后的数据写入文件
QFile outputFile(outputFilePath);
if (outputFile.open(QIODevice::WriteOnly)) {
QByteArray encryptedData = QByteArray::fromStdString(encryptText);
outputFile.write(encryptedData);
outputFile.close();
} else {
qDebug() << "Error: Unable to open output file for writing.";
}
}
QString MainWindow::readAndDecryptFromFile(const QString& encryptedFilePath) {
// 从文件中读取加密后的数据
QString decryptedText;
QFile encryptedFile(encryptedFilePath);
if (encryptedFile.open(QIODevice::ReadOnly)) {
QByteArray encryptedData = encryptedFile.readAll();
encryptedFile.close();
// 解密读取的加密后的数据
std::string decryptedTextStr = RsaPriDecrypt(encryptedData.toStdString(), strPriKey.toStdString());
decryptedText = QString::fromStdString(decryptedTextStr);
} else {
qDebug() << "Error: Unable to open encrypted file for reading.";
}
return decryptedText;
}
/*
制造密钥对:私钥和公钥
**/
void MainWindow::GenerateRSAKey(std::string & out_pub_key, std::string & out_pri_key)
{
size_t pri_len = 0; // 私钥长度
size_t pub_len = 0; // 公钥长度
char *pri_key = nullptr; // 私钥
char *pub_key = nullptr; // 公钥
// 生成密钥对
RSA *keypair = RSA_generate_key(KEY_LENGTH, RSA_3, NULL, NULL);
BIO *pri = BIO_new(BIO_s_mem());
BIO *pub = BIO_new(BIO_s_mem());
// 生成私钥
PEM_write_bio_RSAPrivateKey(pri, keypair, NULL, NULL, 0, NULL, NULL);
// 注意------生成第1种格式的公钥
//PEM_write_bio_RSAPublicKey(pub, keypair);
// 注意------生成第2种格式的公钥(此处代码中使用这种)
PEM_write_bio_RSA_PUBKEY(pub, keypair);
// 获取长度
pri_len = BIO_pending(pri);
pub_len = BIO_pending(pub);
// 密钥对读取到字符串
pri_key = (char *)malloc(pri_len + 1);
pub_key = (char *)malloc(pub_len + 1);
BIO_read(pri, pri_key
没有合适的资源?快使用搜索试试~ 我知道了~
QT 5.15+VS2019 -64位 构建的openssl文件加解密工具
共152个文件
h:136个
dll:6个
cpp:3个
需积分: 5 0 下载量 173 浏览量
2024-04-08
21:15:01
上传
评论
收藏 2.18MB 7Z 举报
温馨提示
QT 5.15+VS2019 -64位 构建的openssl文件加解密工具,可以对大文件进行加解密;
资源推荐
资源详情
资源评论
收起资源包目录
QT 5.15+VS2019 -64位 构建的openssl文件加解密工具 (152个子文件)
mainwindow.cpp 12KB
EncipherMent.cpp 3KB
main.cpp 183B
libcrypto-3-x64.dll 4.63MB
fips.dll 1.77MB
libssl-3-x64.dll 705KB
legacy.dll 188KB
capi.dll 70KB
padlock.dll 57KB
openssl.exe 677KB
obj_mac.h 226KB
ssl.h 124KB
evp.h 94KB
x509v3.h 90KB
x509.h 73KB
tls1.h 71KB
ec.h 65KB
asn1.h 59KB
sslerr.h 46KB
x509_vfy.h 46KB
core_dispatch.h 44KB
cmp.h 39KB
bio.h 39KB
engine.h 39KB
asn1t.h 35KB
cms.h 33KB
ocsp.h 29KB
rsa.h 28KB
core_names.h 28KB
pem.h 25KB
crypto.h 23KB
bn.h 23KB
ct.h 23KB
pkcs7.h 22KB
err.h 21KB
ts.h 20KB
ui.h 19KB
safestack.h 18KB
ecerr.h 17KB
evperr.h 15KB
store.h 15KB
dh.h 15KB
ssl3.h 15KB
asn1err.h 15KB
srp.h 14KB
pkcs12.h 14KB
lhash.h 14KB
crmf.h 13KB
dsa.h 13KB
cmserr.h 12KB
macros.h 11KB
modes.h 11KB
conf.h 11KB
trace.h 10KB
rsaerr.h 9KB
x509v3err.h 9KB
des.h 9KB
e_os2.h 8KB
core.h 8KB
ess.h 8KB
types.h 8KB
x509err.h 7KB
params.h 7KB
kdf.h 7KB
objects.h 7KB
bioerr.h 7KB
tserr.h 6KB
cmperr.h 6KB
decoder.h 6KB
encoder.h 5KB
engineerr.h 5KB
sha.h 5KB
pemerr.h 5KB
pkcs7err.h 5KB
camellia.h 5KB
bnerr.h 5KB
cryptoerr.h 5KB
randerr.h 5KB
storeerr.h 4KB
dherr.h 4KB
seed.h 4KB
mainwindow.h 4KB
aes.h 4KB
self_test.h 4KB
pkcs12err.h 4KB
http.h 4KB
conferr.h 4KB
cterr.h 3KB
rand.h 3KB
crmferr.h 3KB
opensslv.h 3KB
stack.h 3KB
async.h 3KB
ocsperr.h 3KB
idea.h 3KB
configuration.h 3KB
dsaerr.h 3KB
rc5.h 3KB
uierr.h 3KB
cryptoerr_legacy.h 3KB
共 152 条
- 1
- 2
资源评论
搬砖的日子~
- 粉丝: 6
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- html动态爱心代码一(附源码)
- c40539bc-071a-486c-9d52-9d0c18d62dac 4.html
- 基于物理的非视域成像(NLOS)算法,利用了nerf+python源码+文档说明
- yuluer知更鸟.7z(1).001
- python课程设计-基于tensorflow实现的图文生成程序,数据集flickr30k-images+源代码+文档说明+截图
- python作业-基于Flickr30k数据集实现图像文本跨模态搜索python源码+数据集+测试界面+项目说明(高分课程设计)
- 基于Qt实现医院信息管理系统c++源码+文档说明+数据库(期末大作业)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功