Results 1 to 20 of 20

Thread: Crypto++ and Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by jacek View Post
    It will work on windows too, provided that you use .pro files.


    But you have to choose the library, not me. Both of these libraries implement the functionality you need and both are easy to use.

    Crypto++ is a single library, while QCA needs a plugin that will implement desired algorithms, so you will have to compile at least three things to make it work and you will have to distribute more files.
    So, I think crypto++ is better to use than QCA since I need not distribute more files

    I have some idea about to use crypto++ with Qt. Please let me know if I'm wrong

    On windows platform
    1) In the .pro I include these statements

    INCLUDEPATH += <path to crypto++ includes>
    LIBS += -L<path to crypto++ lib directory> -lcrypto++

    Doubt1: "path to crypto++ includes" ---> I dont want to hard code the path. What is the other alternative???

    Probable Solution:According to me I'll create a directory called cryptoInclude and dump all the header files which I downloaded with crypto++. Put this folder(cryptoInclude) whereever my pro file is present, then say INCLUDEPATH += . ./cryptoInclude

    Doubt2: OH, I'm confused what to do with "path to crypto++ lib directory"
    Hmm! I think I need to put cryptopp( Exports Library file ) and cryptopp.dll ( Crypto++ Library Dll ) into a folder named cryptoLib. Put this folder whereever my pro file is present, then say

    LIBS += -L cryptoLib -lcrypto++

    2) Using the .pro file generated above create VC++ Project with this command
    qmake -project -t vcapp -o proFIlename.pro

    3) Load and execute the Qt application using Microsoft Visual Studio .NET 2003.

    DO you think when I want to use a particular class of crypto++ library, my Qt application gets compiled.

    Please bear with me if I'm talking stupid... This is my new experience
    Thanks for your unserstanding

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by vermarajeev View Post
    According to me I'll create a directory called cryptoInclude and dump all the header files which I downloaded with crypto++. Put this folder(cryptoInclude) whereever my pro file is present, then say INCLUDEPATH += . ./cryptoInclude
    It should work.

    Quote Originally Posted by vermarajeev View Post
    I think I need to put cryptopp( Exports Library file ) and cryptopp.dll ( Crypto++ Library Dll ) into a folder named cryptoLib. Put this folder whereever my pro file is present, then say

    LIBS += -L cryptoLib -lcrypto++
    Yes, that's exactly what you have to do, but with just one little correction: since the import library is called cryptopp.lib, you have to use "-lcryptopp".

    Quote Originally Posted by vermarajeev View Post
    Using the .pro file generated above create VC++ Project with this command
    qmake -project -t vcapp -o proFIlename.pro
    Yes, but if you don't use .pro files at all, you can also do it directly in VC++.

    Quote Originally Posted by vermarajeev View Post
    DO you think when I want to use a particular class of crypto++ library, my Qt application gets compiled.
    There shouldn't be any problems with it.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by jacek View Post
    Yes, but if you don't use .pro files at all, you can also do it directly in VC++.
    How can I do this???? I'm using Microsoft Visual Studio .NET 2003 on my system.

    Also one more very improtant problem which is troubling me again and again.

    After the installation of Qt3.3.5 on windows, I should get some buttons at the top like( MOC, Open *.pro files etc) but you wont believe I dont have those butons on my editor. Now if I want to moc a file which has Q_OBJECT in it, I have to explicitly set the properties for each *.h files which is really pain...

    Is there a document which can solve my this problem?????


    I tried the process what I had explained you in above thread. And there are hundreds of warnings....I think I'm going somewhere wrong. I need to find out.

    Waiting eagerly for a reply

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by vermarajeev View Post
    How can I do this???? I'm using Microsoft Visual Studio .NET 2003 on my system.
    Sorry, I don't know, because I don't use VS.

    Quote Originally Posted by vermarajeev View Post
    After the installation of Qt3.3.5 on windows, I should get some buttons at the top like( MOC, Open *.pro files etc) but you wont believe I dont have those butons on my editor.
    Sounds like you didn't install the Qt-VS integration plugin.

  5. #5
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Hi jacek,
    I tried the above process to include the INCLUDEPATH and LIBS as discussed above.

    First of all
    LIBS += -L<path to crypto++ lib directory> -lcryptopp
    is for Qt4 and I'm using Qt3.3.5.

    To correct above I used this
    unix:LIBS += -lcryptopp -L/. ./cryptLib/Debug

    The other important issue is
    On windows I have linked crypto++ lib successfully. It created cryptopp.lib

    then I tried the above process for linux. I get error like cryptopp is not found
    at /usr/lib/Id

    Then I realized, cryptopp.lib cannot be a library file for linux. I need to first creat a library file for linux environment then I can use above commands.

    Now my question is how can I create a library file for linux same as cryptopp.lib on windows

    Please help

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by vermarajeev View Post
    First of all
    LIBS += -L<path to crypto++ lib directory> -lcryptopp
    is for Qt4 and I'm using Qt3.3.5.
    It works for both Qt3 and Qt4.

    Quote Originally Posted by vermarajeev View Post
    To correct above I used this
    unix:LIBS += -lcryptopp -L/. ./cryptLib/Debug
    It should be:
    unix:LIBS += -L/. ./cryptLib/Debug -lcryptopp
    Quote Originally Posted by vermarajeev View Post
    Now my question is how can I create a library file for linux same as cryptopp.lib on windows
    Use the GNUmakefile file that comes with the sources.

  7. #7
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by jacek View Post
    It works for both Qt3 and Qt4..
    Oh I didnt know that. Thanks for your correction

    Quote Originally Posted by jacek View Post
    Use the GNUmakefile file that comes with the sources.
    Which sources???? Where???? What is GNUmakefile????

    Please provide some document or something which can help me to solve my problem....

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by vermarajeev View Post
    Which sources???? Where????
    Crypto++ sources from http://www.cryptopp.com

    You use a library and you don't know where to get it?

    Quote Originally Posted by vermarajeev View Post
    What is GNUmakefile????
    It's a Makefile for GNU make. Every C++ programmer should know what to do with a Makefile.

    Quote Originally Posted by vermarajeev View Post
    Please provide some document or something which can help me to solve my problem....
    http://www.cryptopp.com/
    `man make`

  9. #9
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by jacek View Post
    Crypto++ sources from http://www.cryptopp.com
    You use a library and you don't know where to get it?
    No but I got confused what sources you are taking about...I thought you talked about linux sources...

    Quote Originally Posted by jacek View Post
    It's a Makefile for GNU make. Every C++ programmer should know what to do with a Makefile.
    Yes I know what a makefile is... Again I got confused with the term GNUmakefile....

    Jacek, I'm not a linux expert so having problem to understand the technical terms. But I'm not too bad to grasp it.

    Will let you know the status.

    Thanks for your understanding

  10. #10
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Hi jacek,
    One problem in crypto++5.4 library. In the sample code test.cpp provided by crypto++ library, it tells me
    Qt Code:
    1. - To encrypt a file with AES in CTR mode
    2. cryptest ae input output
    To copy to clipboard, switch view to plain text mode 
    but when I pass these as arguments in command line I get this error
    Qt Code:
    1. "CryptoPP::Exception caught: AES/CTR: 1 is not a valid key length"
    To copy to clipboard, switch view to plain text mode 
    Then I went through the code to check what is wrong?? I realized I need to pass 6 arguments namely
    Qt Code:
    1. cryptest ae key IV input output
    To copy to clipboard, switch view to plain text mode 
    where IV is initialization vector

    Now I have one question, Suppose I have a password "somepassword". How do I calculate key and IV for this somepassword. I tried using some dummy value

    Qt Code:
    1. "2b7e151628aed2a6abf7158809cf4f3c" as my key;
    2. "000102030405060708090a0b0c0d0e0f" as my initialization vector;
    To copy to clipboard, switch view to plain text mode 
    The file got encrypted. But I want to calculate key and IV based on password.

    Please tell me using some sample code. I'll be thankful to you...

    Then there is another problem.
    crypto++ library gives code for only encryption. How can I decrypt the file with same password "somepassword". I tried using decrypt instead of encrypt, but I'm not sure what I'm doing is correct or not.

    Here is the sample code for decryption
    Qt Code:
    1. void AES_CTR_Decrypt(const char *hexKey, const char *hexIV, const char *infile, const char *outfile)
    2. {
    3. SecByteBlock key = HexDecodeString(hexKey);
    4. SecByteBlock iv = HexDecodeString(hexIV);
    5. CTR_Mode<AES>::Decryption aes(key, key.size(), iv);
    6. FileSource(infile, true, new StreamTransformationFilter(aes, new FileSink(outfile)));
    7. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by vermarajeev View Post
    To encrypt a file with AES in CTR mode (...)
    I would use the CBC mode.

    Quote Originally Posted by vermarajeev View Post
    Now I have one question, Suppose I have a password "somepassword". How do I calculate key and IV for this somepassword.
    Well... for 128-bit version of AES you need 128-bit key. For example you can compute MD5 hash of the password, which will give you always exactly 128 bits.

    As for the IV, you can use a constant one, but of course you can also generate it from the password.

    Quote Originally Posted by vermarajeev View Post
    crypto++ library gives code for only encryption. How can I decrypt the file with same password "somepassword". I tried using decrypt instead of encrypt, but I'm not sure what I'm doing is correct or not.
    CTR mode works in such way that the decryption scheme is exactly the same as encryption.

    If you read the docs closely, you will see that CTR_Mode::Decryption is defined as "typedef Encryption Decryption;".

  12. #12
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Crypto++ and Qt

    Quote Originally Posted by jacek View Post
    I would use the CBC mode.
    Please explain why????

    Yes I had the same problem when initially I went through cryptoPP to decide which algorithm to use. I just started to play with AES in CTR mode as that is the only example provided by cryptoPP.. As suggested by you to use AES256 I'm just trying to to achieve the result.

    I know CBC is chaining block cipher and CTR is counter mode. I went through some document explaining AES where I had come across these modes. Let me know why you think you would have used CBC instead of CTR modes?????

    Thanks for your understanding

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
  •  
Qt is a trademark of The Qt Company.