Results 1 to 13 of 13

Thread: need to symmetric encryption in qt app

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

    Default need to symmetric encryption in qt app

    I use Qt with mingw on Windows XP.
    I tried QCA but it doesn't work with Qt (app compiles but gives fatal error when trying to execute it).
    I tried a compiled version of crypto++ too but it has compiling problems (many undefined reference errors).
    I don't know how to get these libs to work.
    please tell me a quick and easy way. I need only a symmetric encryption to encrypt and decrypt a file.
    Last edited by FS Lover; 8th March 2010 at 09:13.

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: need to symmetric encryption in qt app

    I can't believe that qca doesn't work with Qt applications. What is that fatal error that you get when executing your application?
    I'm a rebel in the S.D.G.

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

    Default Re: need to symmetric encryption in qt app

    Quote Originally Posted by lyuts View Post
    I can't believe that qca doesn't work with Qt applications. What is that fatal error that you get when executing your application?
    Qt Code:
    1. #include <QtCrypto>
    2. #include <QtDebug>
    3. #include <stdio.h>
    4. #include <QApplication>
    5.  
    6. int main(int argc, char **argv)
    7. {
    8.  
    9. QApplication app(argc, argv);
    10.  
    11. char ca[1024]="abcdefg";
    12.  
    13. if(!QCA::isSupported("sha1")) printf("SHA1 not supported!\n");
    14. else printf("SHA1 supported.\n");
    15.  
    16. QCA::Hash shaHash("sha1");
    17. qDebug()<<shaHash.type();
    18. shaHash.update(ca, 7);
    19.  
    20. return app.exec();
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (2.01a) ??*???? 16. ???? 23:25:30 2010
    3. ######################################################################
    4.  
    5. TEMPLATE = app
    6. TARGET =
    7. DEPENDPATH += .
    8. INCLUDEPATH += .
    9.  
    10. # Input
    11. SOURCES += main.cpp
    12. CONFIG+=crypto
    13. CONFIG+=console
    To copy to clipboard, switch view to plain text mode 

    it compiles but says that SHA1 is not supported.
    but QCA web site says: QCA has built-in support for the SHA1 and MD5 hash algorithms, and a weak random number source.
    then I get a Windows error:
    qca-error.jpg

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: need to symmetric encryption in qt app

    Did you do
    Qt Code:
    1. QCA::init();
    To copy to clipboard, switch view to plain text mode 
    ?

    Or maybe use QCA Initializer.
    I'm a rebel in the S.D.G.

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

    Default Re: need to symmetric encryption in qt app

    thanks lyuts.
    I tested that adding QCA::init(); and QCA::Initializer I; at the begining of my program.
    now it says SHA1 supported. but I still get Windows error.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: need to symmetric encryption in qt app

    Run your program under GDB then and it'll tell you where the error is.

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

    Default Re: need to symmetric encryption in qt app

    Quote Originally Posted by fatjuicymole View Post
    Run your program under GDB then and it'll tell you where the error is.
    Qt Code:
    1. (gdb) run
    2. Starting program: C:\Documents and Settings\xx\Desktop\qca\test\aes/debug\t.exe
    3.  
    4. [New thread 2824.0x1a4]
    5. SHA1 supported.
    6.  
    7. Program received signal SIGSEGV, Segmentation fault.
    8. 0x10039c99 in qca2!_ZNK3QCA6Base642okEv () from f:\Qt2009.05\qt\bin\qca2.dll
    9. (gdb)
    To copy to clipboard, switch view to plain text mode 

    what now?

  8. #8
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: need to symmetric encryption in qt app

    Try 'backtrace' command in gdb.
    I'm a rebel in the S.D.G.

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

    Default Re: need to symmetric encryption in qt app

    #0 0x10039c99 in qca2!_ZNK3QCA6Base642okEv ()
    from f:\Qt2009.05\qt\bin\qca2.dll
    #1 0x10026c77 in qca2!_ZN3QCA10hexToArrayERK7QString ()
    from f:\Qt2009.05\qt\bin\qca2.dll
    #2 0x1002afc5 in qca2!_ZN3QCA9Algorithm6changeERK7QStringS3_ ()
    from f:\Qt2009.05\qt\bin\qca2.dll
    #3 0x1002b14e in qca2!_ZN3QCA9AlgorithmC2ERK7QStringS3_ ()
    from f:\Qt2009.05\qt\bin\qca2.dll
    #4 0x1003fd50 in qca2!_ZN3QCA4HashC1ERK7QStringS3_ ()
    from f:\Qt2009.05\qt\bin\qca2.dll
    #5 0x004014bd in main (argc=1, argv=0x3d4d88) at main.cpp:18
    line 18 is: QCA::Hash shaHash("sha1");

    it seems that error is internal to qca2.dll. ?

  10. #10
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: need to symmetric encryption in qt app

    Well, it might be qca2.dll's fault by maybe you are providing invalid input that make it crash. Could you paste the complete source code you compiling and running?
    I'm a rebel in the S.D.G.

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

    Default Re: need to symmetric encryption in qt app

    main.cpp
    Qt Code:
    1. #include <QtCrypto>
    2. #include <QtDebug>
    3. #include <stdio.h>
    4. #include <QApplication>
    5.  
    6. int main(int argc, char **argv)
    7. {
    8.  
    9. QCA::init();
    10.  
    11. QApplication app(argc, argv);
    12.  
    13. char ca[1024]="abcdefg";
    14.  
    15. if(!QCA::isSupported("md5")) printf("SHA1 not supported!\n");
    16. else printf("SHA1 supported.\n");
    17.  
    18. QCA::Hash shaHash("sha1");
    19. qDebug()<<shaHash.type();
    20. shaHash.update(ca, 7);
    21.  
    22. return app.exec();
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 
    .pro
    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (2.01a) ??*???? 16. ???? 23:25:30 2010
    3. ######################################################################
    4.  
    5. TEMPLATE = app
    6. TARGET =
    7. DEPENDPATH += .
    8. INCLUDEPATH += .
    9.  
    10. # Input
    11. SOURCES += main.cpp
    12. CONFIG+=crypto
    13. CONFIG+=console
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: need to symmetric encryption in qt app

    Try to make ca a null terminated string and call
    Qt Code:
    1. shaHash.update(ca);
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. shaHash.update(ca, 7);
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

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

    Default Re: need to symmetric encryption in qt app

    I have tried it already.

Similar Threads

  1. Encryption with Qt
    By safknw in forum Newbie
    Replies: 7
    Last Post: 11th July 2012, 15:06
  2. Encryption api in Qt
    By safknw in forum Qt Programming
    Replies: 2
    Last Post: 1st May 2010, 04:25
  3. sqlite+qt+encryption
    By skrzypu in forum Qt Programming
    Replies: 4
    Last Post: 21st October 2009, 14:22
  4. Encryption and decryption
    By vermarajeev in forum General Programming
    Replies: 5
    Last Post: 27th August 2007, 21:17
  5. Basics of Encryption and decryption
    By vermarajeev in forum General Discussion
    Replies: 4
    Last Post: 26th April 2007, 11:53

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.