程序示例精选
Qt RSA OpenSSL C++ Qt加密解密签字通信系统窗体源码
如需安装运行环境或远程调试,可点击 博主头像进入个人主页查看博主联系方式,由专业技术人员远程协助!
前言
这篇博客针对《Qt RSA OpenSSL C++ Qt加密解密签字通信系统窗体源码》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。运行结果
文章目录
一、所需工具软件二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助
一、所需工具软件
1. VS2019, C++2. QT
二、使用步骤
代码如下(示例):
//加密
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(TestRSAEncode_sendout()));
QObject::connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(receiver()));
}
void MainWindow::TestRSASign()
{
GenerateKeyEx();
string strData = "orderId=01010500201502000004reqTime=20150205012727ext=20151120ext2=1";
string strSigned;
if (RSASignAction(strData, strSigned))
{
printf("加签成功\n");
if (RSAVerifyAction(strData, strSigned))
{
printf("验签成功\n");
}
}
}
//发送
string strEncode;
string strDecode;
void MainWindow::TestRSAEncode_sendout()
{
TestRSASign();
//
QString sendoutWord = QString("%1").arg(ui.textEdit->toPlainText());
string strEncodeData = sendoutWord.toStdString();
//string strEncodeData = "你好吗";
GenerateKey();
strEncode = EncodeByBioPublicKey(strEncodeData);
strDecode = DecodeByBioPrivateKey(strEncode);
printf("Old data:%s\n", strEncodeData.c_str());
printf("Encode data:%s\n", strEncode.c_str());
printf("Decode data:%s\n", strDecode.c_str());
std::string encoded64 = base64_encode((const char*)(strEncode.c_str()), strEncode.length());
std::cout << "base64encodedtxt:" << encoded64 << std::endl;
QFile::remove("saveSendOut.txt");
QFile filetxt(QString::fromStdString("saveSendOut_server.txt"));
if (filetxt.open(QIODevice::WriteOnly))
{
QTextStream out(&filetxt);
out.setCodec("UTF-8");
out.flush();
}
filetxt.close();
std::string dir555 = "saveSendOut_server.txt";
std::string filePathCopy = "../client-exe/saveSendOut_server.txt";
std::string filePathCopy2 = "../client-exe/private.pem";
//std::string filePathCopy = "D:/saveSendOut.txt";
QFile::remove(QString::fromStdString(filePathCopy));
QFile::remove(QString::fromStdString(filePathCopy2));
QFile::copy(QString::fromStdString(dir555), QString::fromStdString(filePathCopy));
QFile::copy(QString::fromStdString("private.pem"), QString::fromStdString(filePathCopy2));
}
inline string readFile(const string& filename)
{
ifstream in(filename);
istreambuf_iterator<char> begin(in), end;
string content(begin, end);
in.close();
return content;
}
void MainWindow::receiver()
{
//自接收
string strDecode = DecodeByBioPrivateKey(strEncode);
std::cout << "strDecode: " << strDecode << std::endl;
ui.textEdit_2->setPlainText(title2);
ui.textEdit_4->append(QString::fromStdString("自接收解密: ") + strDecode.c_str());
//远程接收
//QFile file(QString::fromStdString("saveSendOut.txt"));
//if (file.open(QFile::ReadOnly | QFile::Text))
//{
// QTextStream fs(&file);
// QString fileContent(fs.readAll());
// std::cout << "fileContent: " << fileContent.toStdString() << std::endl;
// string strDecodeRemotion = DecodeByBioPrivateKey(fileContent.toStdString());
// ui.textEdit_4->append(QString::fromStdString("远程接收解密: ") + strDecodeRemotion.c_str());
//}
//file.close();
//远程接收
string content = readFile("saveSendOut.txt");
std::string decoded64 = base64_decode(content);
string strDecodeRemotion = DecodeByBioPrivateKey(decoded64);
ui.textEdit_4->append(QString::fromStdString("远程接收解密: ") + strDecodeRemotion.c_str());
}
运行结果
三、在线协助:
如需安装运行环境或远程调试,可点击博主头像,进入个人主页查看博主联系方式,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
博主个人主页:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc
博主所有文章点这里:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc
博主联系方式点这里:https://developer.aliyun.com/profile/expert/rfnzgp3sk3ahc