【问题标题】:Does Qt support RSA encryption?Qt 支持 RSA 加密吗?
【发布时间】:2011-05-13 17:38:54
【问题描述】:

Qt 是否支持 rsa 加密,QSslkey 似乎不起作用。 提前致谢。

【问题讨论】:

    标签: qt encryption rsa


    【解决方案1】:

    Qt 支持 RSA 进行 SSL 连接。没有直接使用 RSA 密钥的接口。

    您可以查看Qt Cryptographic Architecture project,但它看起来不再需要维护了。

    【讨论】:

      【解决方案2】:

      Qt 支持 RSA 加密。您必须向 QSslKey 指明使用的正确算法:http://doc.qt.io/qt-5/qssl.html#KeyAlgorithm-enum

      【讨论】:

        【解决方案3】:

        如果你想加密没有 ssl 依赖的数据,那么你可以使用我的库 Qt-Secret。 该库支持 qmake 构建系统,可以非常轻松地连接到您的项目。


        例如:

        构建

        • git clone 'https://github.com/QuasarApp/Qt-Secret.git'
          cd Qt-Secret
          git submodule update --init --recursive
          qmake -r 
          make -j8
          make test #(for testing)
          

        包括

        对于 qmake 项目

        • cd yourRepo
          git submodule add https://github.com/QuasarApp/Qt-Secret.git # add the repository of Qt-Secret into your repo like submodule
          git submodule update --init --update
          
        • 在你的 pro 文件中包含 Qt-Secret 库的 pri 文件:

          include($$PWD/Qt-Secret/src/Qt-Secret.pri)
          
        • 重建您的项目。

        对于其他构建系统

        • cd yourRepo
          git submodule add https://github.com/QuasarApp/Qt-Secret.git # add the repository of Qt-Secret into your repo like submodule
          git submodule update --init --update
          
        • 添加规则以构建 Qt-Secret。

        • 为您的构建系统添加INCLUDEPATHLIBS
        • 重建您的项目。

        用法

        RSA

        消息的加解密。

        #include <qrsaencryption.h>
        
            QByteArray pub, priv;
            QRSAEncryption e(QRSAEncryption::Rsa::RSA_2048);
            e.generatePairKey(pub, priv);
            QByteArray msg = "test message";
        
            auto encodeData = e.encode(msg, pub);
            auto decodeData = e.decode(encodeData, priv);
        
        

        消息签名的签名和验证。

        #include <qrsaencryption.h>
        
            QByteArray pub, priv;
            QRSAEncryption e;
            e.generatePairKey(pub, priv, QRSAEncryption::Rsa::RSA_128); // or other rsa size 
        
            QByteArray msg = "test message";
        
            auto signedMessage = e.signMessage(msg, priv);
        
            if (e.checkSignMessage(signedMessage, pub)) {
                // message signed success
            }
        
        

        【讨论】:

        • 你应该提到这不是 Qt 的一部分 - 它是一个单独的项目(它似乎只是 GPLv3,而 Qt 在 LGPL 下可用,如果我没记错的话)。
        • @tobySpeight 你没看错。该库必须在 LGPLv3 许可下分发。在code 中可以看到这一点。 GPLv3 许可证选择错误,此问题已解决。
        猜你喜欢
        • 1970-01-01
        • 2019-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-06
        • 2018-07-05
        • 2011-02-08
        • 1970-01-01
        相关资源
        最近更新 更多