开发者

Does Qt support RSA encryption?

Does Qt support rsa encrypti开发者_运维问答on,QSslkey seems doesn't work. thanks in advance.


Qt supports RSA for SSL-connections. There are no interfaces to use RSA keys directly.

You could take a look at the Qt Cryptographic Architecture project, but it does not look to be maintained anymore.


Qt is supporting RSA encryption. You have to indicate to QSslKey the correct algorithm used: http://doc.qt.io/qt-5/qssl.html#KeyAlgorithm-enum


If you want encrypt data without ssl dependencies then you can use my library Qt-Secret. This library supports the qmake build system, which makes it very easy to connect to your project.


For example:

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)
    

Include

For qmake projects

  • 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.

For other build systems

  • 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.

Usage

RSA

Encryption and decryption of messages.

#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);

Signature and verification of the message signature.

#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
    }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜