Qt是否支持RSA加密?

9
Qt是否支持RSA加密,看起来QSslkey无法工作。谢谢。
3个回答

7

2

它不支持通用情况下的RSA加密。例如,您无法使用Qt编写签名/验证算法。 - Alexander Dyagilev

1
如果您想在没有SSL依赖的情况下加密数据,则可以使用我的库Qt-Secret。该库支持qmake构建系统,这使得将其连接到您的项目非常容易。
例如:

Build

  • 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
    
  • Include in your pro file the pri file of Qt-Secret library:

    include($$PWD/Qt-Secret/src/Qt-Secret.pri)
    
  • Rebuild your project.

对于其他构建系统

  • 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
    
  • Add the rule to build Qt-Secret.

  • Add INCLUDEPATH and LIBS for your build system .
  • Rebuild your project.

使用方法

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
    }


1
你应该提到这不是Qt的一部分 - 它是一个独立的项目(它似乎只使用GPLv3许可证,而Qt则可在LGPL下使用,如果我没记错的话)。 - Toby Speight
1
@tobySpeight,你正确地注意到了。 该库必须在LGPLv3许可证下分发。在code中可以看到这一点。GPLv3许可证选择错误,这个问题已经得到解决。 - Andrey Yankovich

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接