-2

I need encrypt and decrypt file (in QT SDK). Encrypt by private key. Decript by public key.

I can't find any usable example on net. Can you push me on the right way?

exo
  • 373
  • 5
  • 22
  • 2
    Possible duplicate of [Qt: data decryption using private/public key](https://stackoverflow.com/questions/39115958/qt-data-decryption-using-private-public-key) – MrEricSir Mar 02 '18 at 21:32
  • 2
    PKI works oposite way. The private key is used for decryption and the public key is used for encryption. In theory the math allows the oposite operations, but tbe result would be not cryptographycally safe anymore – gusto2 Mar 06 '18 at 02:29
  • Thanks for reply... I find any usable solution. I'll add more info in my answear. – exo Mar 09 '18 at 01:39
  • 1
    Note that the data length to be encrypted must be less than the size of the key. This generally means that asymmetric key encryption is not a solution for encryption of files. If an asymmetric key pair is necessary hybrid encryption is the solution. Also consider if symmetric key encryption is sufficient. – zaph Mar 09 '18 at 05:17
  • Thank you for answer. Can you tell me more? I don't understand how you mean it. Especially - the file (length to be encrypted) must be less than the length of the key. In my case, this is not a problem because I will encrypt files with about 200 characters. But if I accidentally need to encrypt a 4MB file, then I can't use asymmetric encryption? – exo Mar 09 '18 at 06:12
  • Ok, I found this thread... https://stackoverflow.com/questions/10007147/getting-a-illegalblocksizeexception-data-must-not-be-longer-than-256-bytes-when – exo Mar 09 '18 at 07:43

1 Answers1

0

I investigate how to work with certificates in QT. Problem is, that it depend by OpenSSL version, windows / linux version and 32/64 bit.

For me I use Windows minGW/32, MSVC2015/32/64 builds.

The First: I use step by step tutorial on youtube "RSA and AES Primer with OpenSSL" (item 150-153) Thank you very much Bryan. https://www.youtube.com/watch?v=LATSg00HaXk

The second: Bryen works on linux. On windows its problem with library names.

  1. You must download or compile OpenSSL libraries. I use download from https://slproweb.com/products/Win32OpenSSL.html Only OpenSSL-Win32.v1.0.2n worked me in combination with tutorial. I did not try my own build. Thank you very much Thomas.

  2. You must add headers and liberaries into your pro file, like this:

LIBS += -LD:/Develop/openssl/OpenSSL-Win32.1.0.2.n.full -llibeay32 
LIBS += -LD:/Develop/openssl/OpenSSL-Win32.1.0.2.n.full -llibssl32 
LIBS += -LD:/Develop/openssl/OpenSSL-Win32.1.0.2.n.full -lssleay32 
INCLUDEPATH += D:/Develop/openssl/OpenSSL-Win32.1.0.2.n.full/include
  1. As you've noticed, libraries are named differently in windows than in linux. Meanwhile in linux you must add libcrypto.a and libssl.a, the names in the windows are completely different (uáááá why???) libeay32,libssl32,ssleay32.

4. If you want work with 64bit version, you must do own build for MSVC2015/17 and use it. I don't test this step at this moment.

exo
  • 373
  • 5
  • 22