Results 1 to 6 of 6

Thread: Problem including openSSL Crypto headers to Qt Application

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Problem including openSSL Crypto headers to Qt Application

    I have an application that needs some crypto libs from OpenSSL.

    the application is uses other SSL functions fine, like https etc (so QT already has SSL built in), but i want to encrypt a password in the INI with blowfish so i need to include some openssl headers.

    I cannot the application to build when i include it..

    Example:
    I tried the following:

    Qt Code:
    1. extern{#include "openssl/evp.h";}
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. #include <openssl/evp.h>
    To copy to clipboard, switch view to plain text mode 

    What is the proper way to declare these includes so Qt will find them?


    One question I have is the use of < > and where the application will look for these files. where should they be located for the app to see them?

    I know that if i use " (quotes) then it looks in the source directory.

    Platform Linux (ubuntu) GCC and Commercial Qt version. 4.4.1

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem including openSSL Crypto headers to Qt Application

    Qt doesn't find includes. Your compiler (or preprocessor to be exact) does. So you have to include the header just like any other include on your system. But is your problem related to including a header file or linking against the crypto library? What is the exact error message you get?

  3. #3
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Problem including openSSL Crypto headers to Qt Application

    Errors:
    Qt Code:
    1. QtTest -L/usr/local/Trolltech/Qt-4.4.1/lib -lQtGui -L/usr/X11R6/lib -lSM -lICE -lXext -lX11 -lQtNetwork -lQtCore -lz -lm -lrt -ldl -lpthread
    2. cryptobfuscate.o: In function `CryptObfuscate::cryptData(QByteArray const&, QByteArray const&, int)':
    3. cryptobfuscate.cpp:(.text+0xb20): undefined reference to `EVP_md5'
    4. cryptobfuscate.cpp:(.text+0xb27): undefined reference to `EVP_bf_cbc'
    5. cryptobfuscate.cpp:(.text+0xb58): undefined reference to `EVP_BytesToKey'
    6. cryptobfuscate.cpp:(.text+0xb6e): undefined reference to `EVP_CIPHER_CTX_init'
    7. cryptobfuscate.cpp:(.text+0xb73): undefined reference to `EVP_bf_cbc'
    8. cryptobfuscate.cpp:(.text+0xb9c): undefined reference to `EVP_CipherInit_ex'
    9. cryptobfuscate.cpp:(.text+0xbd6): undefined reference to `EVP_CipherUpdate'
    10. cryptobfuscate.cpp:(.text+0xc00): undefined reference to `EVP_CipherFinal_ex'
    11. cryptobfuscate.cpp:(.text+0xc38): undefined reference to `EVP_CIPHER_CTX_cleanup'
    12. collect2: ld returned 1 exit status
    13. make: *** [printsend] Error 1
    To copy to clipboard, switch view to plain text mode 

    This is the code that this is referring to:

    Qt Code:
    1. //OpenSSL blowfish encryption
    2.  
    3. //TODO: Modify to include other encryption algo - (passed by name)
    4.  
    5. QByteArray CryptObfuscate::cryptData(const QByteArray& data, const QByteArray& password, int cmd)
    6.  
    7. {
    8.  
    9.  
    10.  
    11.  
    12.  
    13. const char initValue[] = "5f7a20de";
    14.  
    15. const char salt[] = "72jadg07";
    16.  
    17.  
    18.  
    19. unsigned char *buf;
    20.  
    21. unsigned char *ebuf;
    22.  
    23. int ebuflen,padlen;
    24.  
    25. unsigned char iv[EVP_MAX_IV_LENGTH], key[EVP_MAX_KEY_LENGTH];
    26.  
    27. EVP_CIPHER_CTX ectx;
    28.  
    29.  
    30.  
    31. buf = new unsigned char[data.size()];
    32.  
    33. ebuf = new unsigned char[data.size() + EVP_MAX_BLOCK_LENGTH ];
    34.  
    35.  
    36.  
    37. memcpy(iv,initValue,sizeof(iv));
    38.  
    39.  
    40.  
    41. if(EVP_BytesToKey(EVP_bf_cbc(), EVP_md5(), reinterpret_cast< const unsigned char*>(salt),
    42.  
    43. reinterpret_cast< const unsigned char*>(password.constData()) , password.size(), 1, key, iv) <= 0)
    44.  
    45. return QByteArray();
    46.  
    47.  
    48.  
    49. EVP_CIPHER_CTX_init(&ectx);
    50.  
    51. truncated . . . .
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem including openSSL Crypto headers to Qt Application

    This is not a problem with including, this is a problem with linking. Add LIBS+=-lcrypto to your project file and rerun qmake.

  5. The following 2 users say thank you to wysota for this useful post:

    nbkhwjm (19th November 2008), TCB13 (30th August 2011)

  6. #5
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Problem including openSSL Crypto headers to Qt Application

    Ok that worked to complete compile, but now SegFault on main(), i'll work through that...

    Thanks

  7. #6
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Problem including openSSL Crypto headers to Qt Application

    All fixed thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.