QuasarApp / Qt-Secret

Simple encryption library supporting RSA and AES algorithms.
https://quasarapp.ddns.net:3031/docs/QuasarApp/Qt-Secret/latest/index.html
GNU Lesser General Public License v3.0
243 stars 69 forks source link

Using on windows #59

Closed radimkohout closed 4 years ago

radimkohout commented 4 years ago

Hi, how can I use this library in qt creator on windows? I can't do it. Thanks Radim Kohout

EndrII commented 4 years ago

Hi

For the correct incude you need:

incude in qtCreator

youProjectFolder.file = path/to/yuorProject.pro

 * Open the Master project folder in git console. If git not install then install it [this](https://git-scm.com/download/win)
 * run: git submodule add https://github.com/QuasarApp/Qt-Secret.git 
 * run: git submodule update --init --recursive
 * Open Master.pro
 * Add Qt-Secret library like submproject of Master
``` qmake
SUBDIRS += \
           youProjectFolder \
          Qt-Secret \

youProjectFolder.file = path/to/yuorProject.pro

 * Rebuild Master project
 * All done!. Now you nead to build only master project, because it will build both your project and the project Qt-Secret. QT-Secret will already be included to your project and you will be able to use it in your code. 

For Example you can see my [master](https://github.com/QuasarApp/Qt-Secret/blob/master/Qt-Secret.pro) project and incude library [lines](https://github.com/QuasarApp/Qt-Secret/blob/a6828ea53d8b6a5f60def149fee2792ae6d7d774/Qt-Secret-GUI/Qt-Secret-GUI.pro#L22). 
EndrII commented 4 years ago

@radimkohout if this instruction helped. i Add it to README file. let me know what you got as a result.

radimkohout commented 4 years ago

It works( You forgot to use "git init")

EndrII commented 4 years ago

No. I am use "git submodule update --init --recursive" this command initializes along with a full upgrade.

can i close the topic?

radimkohout commented 4 years ago

Nope, when I use QRSAEncryption e(QRSAEncryption::Rsa::RSA_2048); 13:36:24: The program has unexpectedly finished. 13:36:24: The process was ended forcefully. (in main.h, qrsaencryption.h is included, when I comment this, it works. It is example from readme)

EndrII commented 4 years ago

@radimkohout Yes. This is not a valid example. I updated README. See a new example :

#include <qrsaencryption.h>
#include <QDebug>

bool testEncryptAndDecryptExample() {

    QByteArray pub, priv;
    QRSAEncryption e(QRSAEncryption::Rsa::RSA_2048);
    e.generatePairKey(pub, priv); // or other rsa size

    QByteArray msg = "test message";

    auto encryptMessage = e.encode(msg, pub);

    if (encryptMessage == msg)
        return false;

    auto decodeMessage = e.decode(encryptMessage, priv);

    return decodeMessage == msg;
}

int main() {
    if (testEncryptAndDecryptExample()) {
        qInfo() << "Success!";
    }
}
radimkohout commented 4 years ago

Not better. This is my code: `

include "mainwindow.h"

include

include "myserver.h"

include

include

include

bool testEncryptAndDecryptExample() {

QByteArray pub, priv;
QRSAEncryption e(QRSAEncryption::Rsa::RSA_2048);
e.generatePairKey(pub, priv); // or other rsa size

QByteArray msg = "test message";

auto encryptMessage = e.encode(msg, pub);

if (encryptMessage == msg)
    return false;

auto decodeMessage = e.decode(encryptMessage, priv);

return decodeMessage == msg;

} int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); MyServer S; if (testEncryptAndDecryptExample()) { qInfo() << "Success!"; } return a.exec(); } ` The only thing I am getting are 37 warnings like this: Makefile.GMP:80: warning: ignoring old recipe for target 'sub-tests-tests-pro-qmake_all'

EndrII commented 4 years ago

Show me your build log or give me your repository with your code. So that I can find a problem.

radimkohout commented 4 years ago

https://github.com/radimkohout/RServer/

EndrII commented 4 years ago

Sorry, I made some mistakes when writing the instructions, it’s important for us to build the dependencies first and then only your project. I updated the instructions. You need to rewrite your Master.pro with instructions

incude Qt-Secret in qtCreator

TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += \
           youProjectFolder

youProjectFolder.file = path/to/yuorProject.pro

SUBDIRS += \ Qt-Secret \ youProjectFolder \

youProjectFolder.file = path/to/yuorProject.pro

 * Open YouProject.pro
 * Include in your MyProject.pro file the pri file of Qt-Secret library (insert ito end of file next line :)
``` qmake
 include($$PWD/../Qt-Secret/src/Qt-Secret.pri)

For Example you can see my master project and incude library lines.

EndrII commented 4 years ago

just add

TEMPLATE = subdirs
CONFIG += ordered

and swap Qt-Secret and YourProjectFolder. So that Qt-Secret would be the first.

radimkohout commented 4 years ago

Fixed... See my repo. But I am getting another error: error: [Makefile:133: sub-youProjectFolder-file-make_first-ordered] Error 2

EndrII commented 4 years ago

you forgot about CONFIG + = ordered in master.pro

TEMPLATE = subdirs
CONFIG += ordered
radimkohout commented 4 years ago

Nope, it was one-time compilation error. Rebuild, and it works. Thanks. Everything's working.

EndrII commented 4 years ago

@radimkohout it is still extremely important for you to add 'CONFIG + = ordered' because this configuration forces qmake to build the projects in the order you specify. If this setting does not exist, then you will now receive periodically compilation errors.

radimkohout commented 4 years ago

I have It there.