Qt RSA OpenSSL C++ Qt加密解密签字通信系统窗体源码

简介: Qt RSA OpenSSL C++ Qt加密解密签字通信系统窗体源码
程序示例精选
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
相关文章
|
2月前
|
设计模式 缓存 编译器
【C++ 元对象系统03】深入探索Qt反射:从原理到实践
【C++ 元对象系统03】深入探索Qt反射:从原理到实践
60 4
|
2月前
|
安全 前端开发 C++
C++视角下的Qt按钮:从基础应用到高级定制(二)
C++视角下的Qt按钮:从基础应用到高级定制
45 2
|
2月前
|
XML JSON 算法
C++视角下的Qt按钮:从基础应用到高级定制(一)
C++视角下的Qt按钮:从基础应用到高级定制
92 2
|
2月前
|
Linux 数据处理 C++
Linux系统编程 C/C++ 以及Qt 中的零拷贝技术: 从底层原理到高级应用(一)
Linux系统编程 C/C++ 以及Qt 中的零拷贝技术: 从底层原理到高级应用
80 0
|
2月前
|
存储 Linux 测试技术
无效数据处理之道:Linux系统编程C/C++实践探索(三)
无效数据处理之道:Linux系统编程C/C++实践探索
17 0
|
2月前
|
存储 测试技术 Linux
无效数据处理之道:Linux系统编程C/C++实践探索(二)
无效数据处理之道:Linux系统编程C/C++实践探索
31 0
|
2月前
|
存储 Linux API
Linux系统编程 C/C++ 以及Qt 中的零拷贝技术: 从底层原理到高级应用(三)
Linux系统编程 C/C++ 以及Qt 中的零拷贝技术: 从底层原理到高级应用
32 1
|
2月前
|
消息中间件 Linux 数据处理
Linux系统编程 C/C++ 以及Qt 中的零拷贝技术: 从底层原理到高级应用(二)
Linux系统编程 C/C++ 以及Qt 中的零拷贝技术: 从底层原理到高级应用
34 1
|
19天前
|
存储 算法 Linux
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
42 6
|
2月前
|
编译器 API 数据安全/隐私保护
深入对比:Qt 的 QFile/QFileInfo 和与 C++17 Filesystem 和标准文件流 的细节剖析
深入对比:Qt 的 QFile/QFileInfo 和与 C++17 Filesystem 和标准文件流 的细节剖析
101 3

推荐镜像

更多