Reputation: 139
I been trying to use the Qt Encryption libraries and have been having trouble. The ones that ship with Qt (QCryptographicHash) work well but only support hash schemes that are insecure like md5 and SHA1, there is no SHA256 for example.
I found the Qt Cryptographic Architecture (QCA) which has much more features. I got the libraries from the Delta XMPP Project site. http://delta.affinix.com/qca/
The link to the QCA library is http://delta.affinix.com/download/qca/2.0/qca-2.0.3.tar.bz2
It is the newest version of the QCA Libary.
The instruction are as follows.
Installing QCA
QCA requires Qt 4.2 or greater.
For Windows:
configure
nmake (or make)
installwin
Using newest Qt everything. Everything works great in Qt except this library. I use Windows XP. I followed the installation instructions and got no errors.
The problem is that I get errors when I try to use any code that has anything to do with the QCA library. I would really appreciate any help getting this lib to work.
Here is my code.
The project file.
#-------------------------------------------------
#
# Project created by QtCreator 2011-11-14T14:23:21
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = kde_crypto2
CONFIG += console
CONFIG -= app_bundle
CONFIG += crypto
TEMPLATE = app
SOURCES += main.cpp
The source file.
#include <QtCore/QCoreApplication>
#include <QTextStream>
#include <QString>
#include <QtCrypto/QtCrypto>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream t(stdout);
if(!QCA::isSupported("sha1"))
t << "SHA1 not supported!\n";
else
{
QByteArray fillerString;
fillerString.fill('a', 1000);
QCA::Hash shaHash("sha1");
for (int i=0; i<1000; i++)
shaHash.update(fillerString);
QByteArray hashResult = shaHash.final();
if ( "34aa973cd4c4daa4f61eeb2bdbad27316534016f" == QCA::arrayToHex(hashResult) )
{
t << "big SHA1 is OK\n";
}
else
{
t << "big SHA1 failed\n";
}
}
return a.exec();
}
Error code is
error: conversion from 'QCA::MemoryRegion' to non-scalar type 'QByteArray' requested
EDIT (UPDATE) I did not include the --debug-and-release flag when compiling the library. After re-compiling thelibrary with this flag I no longer get errors while compiling my code. However, when I run my code the application crashes when ever any line is reached that uses the QCA library. Therefore I believe there is either something wrong with the library or the way it is installed.
The error code when running is:
ASSERT: "global" in file qca_core.cpp, line 260
Upvotes: 2
Views: 3588
Reputation: 301
The following will remove the error.
QByteArray hashResult = hash.final().toByteArray();
Upvotes: 0
Reputation: 12321
If you are compiling Qt
from source you could try this merge request
integrated Aaron Gifford BSD licensed SHA-256, SHA-384 and SHA-512 functions similar way than original SHA-1 and MD-5 has been done.
I have not tried it myself but the code seems ok and it from the comments I can tell that it will be included in a later release.
Upvotes: 0
Reputation: 2948
Looks like the cause of the error is that you get a MemoryRegion
with shaHash.final()
and you try to stuff it into a QByteArray
. Try adding a .toByteArray()
after the final()
call. See http://delta.affinix.com/docs/qca/classQCA_1_1MemoryRegion.html
Whether it makes sense to use QCA (and its maintenance state) I don't know though.
Upvotes: 0