PDA

View Full Version : need to symmetric encryption in qt app



FS Lover
8th March 2010, 08:55
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.

lyuts
8th March 2010, 20:04
I can't believe that qca doesn't work with Qt applications. What is that fatal error that you get when executing your application?

FS Lover
9th March 2010, 07:31
I can't believe that qca doesn't work with Qt applications. What is that fatal error that you get when executing your application?

#include <QtCrypto>
#include <QtDebug>
#include <stdio.h>
#include <QApplication>

int main(int argc, char **argv)
{

QApplication app(argc, argv);

char ca[1024]="abcdefg";

if(!QCA::isSupported("sha1")) printf("SHA1 not supported!\n");
else printf("SHA1 supported.\n");

QCA::Hash shaHash("sha1");
qDebug()<<shaHash.type();
shaHash.update(ca, 7);

return app.exec();

}


################################################## ####################
# Automatically generated by qmake (2.01a) ??*???? 16. ???? 23:25:30 2010
################################################## ####################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp
CONFIG+=crypto
CONFIG+=console


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:
4386

lyuts
9th March 2010, 07:35
Did you do
QCA::init();?

Or maybe use QCA Initializer (http://delta.affinix.com/docs/qca/classQCA_1_1Initializer.html).

FS Lover
9th March 2010, 07:59
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.

squidge
9th March 2010, 08:02
Run your program under GDB then and it'll tell you where the error is.

FS Lover
9th March 2010, 08:45
Run your program under GDB then and it'll tell you where the error is.


(gdb) run
Starting program: C:\Documents and Settings\xx\Desktop\qca\test\aes/debug\t.exe

[New thread 2824.0x1a4]
SHA1 supported.

Program received signal SIGSEGV, Segmentation fault.
0x10039c99 in qca2!_ZNK3QCA6Base642okEv () from f:\Qt2009.05\qt\bin\qca2.dll
(gdb)

what now?

lyuts
9th March 2010, 09:02
Try 'backtrace' command in gdb.

FS Lover
9th March 2010, 09:28
#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. ?

lyuts
9th March 2010, 09:43
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?

FS Lover
9th March 2010, 10:06
main.cpp

#include <QtCrypto>
#include <QtDebug>
#include <stdio.h>
#include <QApplication>

int main(int argc, char **argv)
{

QCA::init();

QApplication app(argc, argv);

char ca[1024]="abcdefg";

if(!QCA::isSupported("md5")) printf("SHA1 not supported!\n");
else printf("SHA1 supported.\n");

QCA::Hash shaHash("sha1");
qDebug()<<shaHash.type();
shaHash.update(ca, 7);

return app.exec();

}

.pro

################################################## ####################
# Automatically generated by qmake (2.01a) ??*???? 16. ???? 23:25:30 2010
################################################## ####################

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp
CONFIG+=crypto
CONFIG+=console

lyuts
9th March 2010, 10:13
Try to make ca a null terminated string and call

shaHash.update(ca);
instead of

shaHash.update(ca, 7);

FS Lover
9th March 2010, 10:38
I have tried it already.