Results 1 to 15 of 15

Thread: Compiling & using Crypto++ with mingw version of Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Compiling & using Crypto++ with mingw version of Qt

    Hi pals!
    I personally had much trouble with these.
    apparently compiled version of crypto++ (cryptopp530win32win64.zip) is build using MSVC and does not work with mingw.
    fortunately I could get it to work finally.
    so I tell you too, step by step, how to do it.

    first download the cryptopp552.zip (crypto++ v5.5.2 sources)
    why cryptopp552.zip? apparently this is the latest version that is successfully compiled with mingw.

    extract the contents of the cryptopp552.zip to C:\cryptopp552

    edit the C:\cryptopp552\fipstest.cpp and replace every 'OutputDebugString' with 'OutputDebugStringA'. (3 replacements in total)
    don't forget to save it!

    delete the C:\cryptopp552\GNUmakefile

    open the Qt command prompt (I used that of the Qt SDK 2009.05)
    input the following commands at the Qt command line:
    c:
    cd \cryptopp552
    qmake -project

    open the cryptopp552.pro (that is now created in C:\cryptopp552)
    in it:
    change TEMPLATE = app to TEMPLATE = lib
    add a line containing LIBS += -lws2_32 at the end.

    type the following commands at the Qt command line:
    qmake
    mingw32-make all

    wait for the build process to finish (may take many minutes)

    now we should have files named libcryptopp552.a and cryptopp552.dll in directories C:\cryptopp552\release and C:\cryptopp552\debug

    copy the C:\cryptopp552\release\libcryptopp552.a to <Qt dir>\lib
    note that there is another directory named lib one level higher in the Qt SDK installation dir. So don't confuse them please.
    copy the C:\cryptopp552\release\cryptopp552.dll to <Qt dir>\bin
    note that there is another directory named bin one level higher in the Qt SDK installation dir. So don't confuse them please.

    create a directory named cryptopp in <Qt dir>\include.
    copy all header (.h) files from the C:\cryptopp552 to <Qt dir>\include\cryptopp.

    now we can test crypto++ and see how to use it in our Qt programs.

    first example is a program that computes an MD5 hash (of a hard coded string):

    main.cpp
    Qt Code:
    1. #include <iostream>
    2.  
    3. #define CRYPTOPP_DEFAULT_NO_DLL
    4. #include <cryptopp/dll.h>
    5. #ifdef CRYPTOPP_WIN32_AVAILABLE
    6. #include <windows.h>
    7. #endif
    8. #include <cryptopp/md5.h>
    9.  
    10. USING_NAMESPACE(CryptoPP)
    11. USING_NAMESPACE(std)
    12. const int MAX_PHRASE_LENGTH=250;
    13.  
    14. int main(int argc, char *argv[]) {
    15.  
    16. CryptoPP::MD5 hash;
    17. byte digest[ CryptoPP::MD5::DIGESTSIZE ];
    18. std::string message = "Hello World!";
    19.  
    20. hash.CalculateDigest( digest, (const byte*)message.c_str(), message.length());
    21.  
    22. CryptoPP::HexEncoder encoder;
    23. std::string output;
    24. encoder.Attach( new CryptoPP::StringSink( output ) );
    25. encoder.Put( digest, sizeof(digest) );
    26. encoder.MessageEnd();
    27.  
    28. std::cout << "Input string: " << message << std::endl;
    29. std::cout << "MD5: " << output << std::endl;
    30.  
    31. return 0;
    32. }
    To copy to clipboard, switch view to plain text mode 

    code from: http://www.cryptopp.com/wiki/Hash_Functions

    remember that you should add these lines to its .pro file before starting to build it:
    LIBS += -lcryptopp552
    CONFIG+=console

    the program should print these on the console window:
    Input string: Hello World!
    MD5: ED076287532E86365E841E92BFC50D8C

    second example is a program that takes 3 arguments at the command line.
    arguments are file names.
    the program then prompts for a Passphrase and then stores an encrypted version of the first file in the second file and then stores the result of decrypting the second file in the third file.
    sample command line I used: release\cryptopptest.exe 1.jpg 2.jpg 3.jpg

    Qt Code:
    1. #include <iostream>
    2.  
    3. #define CRYPTOPP_DEFAULT_NO_DLL
    4. #include <cryptopp/dll.h>
    5. #include <cryptopp/default.h>
    6. #ifdef CRYPTOPP_WIN32_AVAILABLE
    7. #include <windows.h>
    8. #endif
    9.  
    10. USING_NAMESPACE(CryptoPP)
    11. USING_NAMESPACE(std)
    12.  
    13. const int MAX_PHRASE_LENGTH=250;
    14.  
    15. void EncryptFile(const char *in,
    16. const char *out,
    17. const char *passPhrase);
    18. void DecryptFile(const char *in,
    19. const char *out,
    20. const char *passPhrase);
    21.  
    22.  
    23. int main(int argc, char *argv[])
    24. {
    25. try
    26. {
    27. char passPhrase[MAX_PHRASE_LENGTH];
    28. cout << "Passphrase: ";
    29. cin.getline(passPhrase, MAX_PHRASE_LENGTH);
    30. EncryptFile(argv[1], argv[2], passPhrase);
    31. DecryptFile(argv[2], argv[3], passPhrase);
    32. }
    33. catch(CryptoPP::Exception &e)
    34. {
    35. cout << "\nCryptoPP::Exception caught: "
    36. << e.what() << endl;
    37. return -1;
    38. }
    39. catch(std::exception &e)
    40. {
    41. cout << "\nstd::exception caught: " << e.what() << endl;
    42. return -2;
    43. }
    44. }
    45.  
    46.  
    47. void EncryptFile(const char *in,
    48. const char *out,
    49. const char *passPhrase)
    50. {
    51. FileSource f(in, true, new DefaultEncryptorWithMAC(passPhrase,
    52. new FileSink(out)));
    53. }
    54.  
    55. void DecryptFile(const char *in,
    56. const char *out,
    57. const char *passPhrase)
    58. {
    59. FileSource f(in, true,
    60. new DefaultDecryptorWithMAC(passPhrase, new FileSink(out)));
    61. }
    62.  
    63. RandomPool & GlobalRNG()
    64. {
    65. static RandomPool randomPool;
    66. return randomPool;
    67. }
    68. int (*AdhocTest)(int argc, char *argv[]) = NULL;
    To copy to clipboard, switch view to plain text mode 

    code from: http://www.codeguru.com/cpp/misc/mis...le.php/c11953/

    remember that you should add these lines to its .pro file before starting to build it:
    LIBS += -lcryptopp552
    CONFIG+=console

    --------------------------------

    I appreciate your feedback.
    good luck!

  2. The following 2 users say thank you to FS Lover for this useful post:

    programmer.huang (11th March 2010), sedi (16th January 2018)

  3. #2
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    this is a function I wrote & tested for encrypting an in memory file stored in a QByteArray.
    it takes a QByteArray and a passPhrase and then encrypts the contents of the QByteArray.
    Crypto++ encryption class which it uses is DefaultEncryptorWithMAC and according to the reference doc it uses Password-Based Encryptor using DES-EDE2 and HMAC/SHA-1.

    Qt Code:
    1. void encrypt(QByteArray &in_out, const char *passPhrase) {
    2.  
    3. string tmp;
    4. StringSource s((const byte *)in_out.constData(), in_out.size(), true, new DefaultEncryptorWithMAC(passPhrase, new StringSink(tmp)));
    5. in_out.clear();
    6. in_out.append(QByteArray(tmp.c_str(), tmp.size()));
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    for decrypting u simply need to a DefaultDecryptorWithMAC instead of the DefaultEncryptorWithMAC:

    Qt Code:
    1. void decrypt(QByteArray &in_out, const char *passPhrase) {
    2.  
    3. string tmp;
    4. StringSource s((const byte *)in_out.constData(), in_out.size(), true, new DefaultDecryptorWithMAC(passPhrase, new StringSink(tmp)));
    5. in_out.clear();
    6. in_out.append(QByteArray(tmp.c_str(), tmp.size()));
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    I am new to Crypto++ (and to cryptography in general) and haven't read the entire crypto++'s reference; Any idea about a better code is welcome.
    Last edited by FS Lover; 11th March 2010 at 20:24.

  4. #3
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    compiled (with mingw) Crypto++ lib and include files: http://www.4shared.com/file/24082421...mingw-bin.html (12 MB)

    and another download with no debug lib included: http://www.4shared.com/file/24082839...n-nodebug.html (2.5 MB)

  5. #4
    Join Date
    Jun 2010
    Posts
    102
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    Quote Originally Posted by FS Lover View Post
    compiled (with mingw) Crypto++ lib and include files: http://www.4shared.com/file/24082421...mingw-bin.html (12 MB)

    and another download with no debug lib included: http://www.4shared.com/file/24082839...n-nodebug.html (2.5 MB)
    if i want use Vmac in Crypto Plus Plus On QT then how do i do ?

    _http://www.cryptopp.com/docs/ref/class_v_m_a_c.html

  6. #5
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    Man your tutorial is just what a newbie needs
    else i would have been a goner


    Thank you really from my heart

    I love working in Qt , the only thing i Fell Qt lacks is real tutorials of using external plugins,library or dll's etc
    But you really made my day today
    thanks again

  7. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    Quote Originally Posted by udit View Post
    the only thing i Fell Qt lacks is real tutorials of using external plugins,library or dll's etc
    That's because this has almost nothing to do with Qt.

  8. #7
    Join Date
    May 2009
    Posts
    147
    Thanks
    11
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    Crypto++ v5.5.1 Reference Manual: http://www.4shared.com/file/S5jvueo-...oPP551Ref.html

  9. #8
    Join Date
    Feb 2011
    Location
    The Netherlands
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    Thanks for all the help in this thread!
    For all who might like, Crypto++ v 5.6.1 compiled on Windows 7 (32 bit) with the latest Qt 4.7 2010.05
    http://jinx.etv.cx/media/cryptopp561-mingw32-qt47.zip (12.2 MB)

    There might be a header or two too much in the includes etc, but they seem to be working.

  10. #9
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling & using Crypto++ with mingw version of Qt

    could you tell me waht would be the dependency when i run this program on different machine what parts of cryptolibrary need to be with the executable

Similar Threads

  1. Don't configure under vs command prompt when building gcc (mingw) version of qt
    By piotr.dobrogost in forum Installation and Deployment
    Replies: 4
    Last Post: 1st February 2011, 20:28
  2. Windows minGW g++ version 3.4.5
    By PUK_999 in forum Newbie
    Replies: 4
    Last Post: 21st August 2009, 22:38
  3. Replies: 2
    Last Post: 12th July 2009, 08:24
  4. using the qt 4.4.0 evaluation version with MinGw
    By dano in forum Installation and Deployment
    Replies: 4
    Last Post: 4th July 2008, 16:02
  5. Wich MinGW Version should i use for QT 4.4.0?
    By raphaelf in forum Installation and Deployment
    Replies: 3
    Last Post: 27th May 2008, 14:29

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.