Hi All,
I am a total newbie. I am going crazy with a problem. I am using QCA and qca-gnupg.
I am trying to simply import a secret key. The code is:
Header File:
#ifndef MYGPG_H
#define MYGPG_H
#include <QDebug>
#include <QObject>
#include <QtCrypto>
class PassphraseHandler
: public QObject{
Q_OBJECT
public:
QCA::EventHandler handler;
PassphraseHandler
(QObject *parent
= 0);
private slots:
void eh_eventReady(int id, const QCA::Event &event);
};
{
Q_OBJECT
public:
myKeyLoader
(QObject* parent
= NULL);
public slots:
void start();
};
#endif // MYGPG_H
#ifndef MYGPG_H
#define MYGPG_H
#include <QDebug>
#include <QObject>
#include <QtCrypto>
class PassphraseHandler: public QObject
{
Q_OBJECT
public:
QCA::EventHandler handler;
PassphraseHandler(QObject *parent = 0);
private slots:
void eh_eventReady(int id, const QCA::Event &event);
};
class myKeyLoader : public QObject
{
Q_OBJECT
public:
myKeyLoader(QObject* parent = NULL);
public slots:
void start();
};
#endif // MYGPG_H
To copy to clipboard, switch view to plain text mode
Source file:
#include "mygpg.h"
PassphraseHandler
::PassphraseHandler(QObject *parent
) : QObject(parent
){
connect(&handler, SIGNAL(eventReady(int, const QCA::Event &)),
SLOT(eh_eventReady(int, const QCA::Event &)));
handler.start();
}
void PassphraseHandler::eh_eventReady(int id, const QCA::Event &event)
{
if(event.type() == QCA::Event::Password)
{
QCA::SecureArray pass;
QCA::ConsolePrompt prompt;
prompt.getHidden("Passphrase");
prompt.waitForFinished();
pass = prompt.result();
handler.submitPassword(id, pass);
}
else
handler.reject(id);
}
myKeyLoader
::myKeyLoader(QObject* parent
){
}
void myKeyLoader::start()
{
QCA::ConvertResult* result = new QCA::ConvertResult;
QCA::PGPKey myPgpKey = QCA::PGPKey::fromFile("private_key.pkr",result,"qca-gnupg");
qDebug()<<"pgp:"<<*result;
qDebug()<<"can decrypt:"<<myPgpKey.inKeyring();
}
#include "mygpg.h"
PassphraseHandler::PassphraseHandler(QObject *parent) : QObject(parent)
{
connect(&handler, SIGNAL(eventReady(int, const QCA::Event &)),
SLOT(eh_eventReady(int, const QCA::Event &)));
handler.start();
}
void PassphraseHandler::eh_eventReady(int id, const QCA::Event &event)
{
if(event.type() == QCA::Event::Password)
{
QCA::SecureArray pass;
QCA::ConsolePrompt prompt;
prompt.getHidden("Passphrase");
prompt.waitForFinished();
pass = prompt.result();
handler.submitPassword(id, pass);
}
else
handler.reject(id);
}
myKeyLoader::myKeyLoader(QObject* parent)
:QObject(parent)
{
}
void myKeyLoader::start()
{
QCA::ConvertResult* result = new QCA::ConvertResult;
QCA::PGPKey myPgpKey = QCA::PGPKey::fromFile("private_key.pkr",result,"qca-gnupg");
qDebug()<<"pgp:"<<*result;
qDebug()<<"can decrypt:"<<myPgpKey.inKeyring();
}
To copy to clipboard, switch view to plain text mode
main.cpp:
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QTimer>
#include "mygpg.h"
int main(int argc, char *argv[])
{
QCA::Initializer init;
if(!QCA::isSupported("openpgp"))
{
}
else
{
PassphraseHandler passphraseHandler;
myKeyLoader* keyLoader = new myKeyLoader();
QTimer::singleShot(0,keyLoader,
SLOT(start
()));
}
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QTimer>
#include "mygpg.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCA::Initializer init;
if(!QCA::isSupported("openpgp"))
{
}
else
{
PassphraseHandler passphraseHandler;
myKeyLoader* keyLoader = new myKeyLoader();
QTimer::singleShot(0,keyLoader,SLOT(start()));
}
return a.exec();
}
To copy to clipboard, switch view to plain text mode
I get the following dignostic string:
"GPGProc: Running: [C:\Program Files\GNU\GnuPG\gpg.exe --no-tty --no-default-keyring --keyring C:\prj\qcaGnupg\qca_gnupg_tmp.JS4036.gpg --secret-keyring C:\prj\qcaGnupg\qca_gnupg_tmp.Oh4036.gpg --import]
GPGProc: Process started
GPGProc: Process finished: 2
GPGProc: Done
GPG Process Finished: exitStatus=2
stdout: []
stderr: [gpg: can't open `C:\prj\qcaGnupg\qca_gnupg_tmp.Oh4036.gpg'
gpg: key 169C844F: secret key not found: file open error
gpg: error reading `[stdin]': file open error
gp..."
But if I run the same command at the dos prompt it runs sucessfully, following is the output:
C:\prj\qcaGnupg>gpg.exe --no-tty --no-default-keyring --keyring C:\prj\qcaGnupg\qca_gnupg_tmp.JS4036.gpg --secret-keyring C:\prj\qcaGnupg\qca_gnupg_tmp.Oh4036.gpg --import
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: BCPG v1.45
lQIGBE0hbIABBAChhmP3pkI+XWlow0q9a3ZmwWLpPjQRs9oaNO CzMwAA5p54gNT7
5UCBv9K5uqreilyV4HZLSimKGW6JkvFBNCcxVc+rK2cqsvRZAw 0D2uJK1Lone/IW
AcfpVCqJyB7UtpPUGNqZdP90tNNIr1BBsOo25Ixsi3ujBHTLbb j0yP39JwARAQAB
/gcDApZudzSyZJYEYM9e7uuo5tq3YaX9G0kwnaMQitPBAVJU5UM tsR5/rJgiHKdL
4iOXaqkbm5Ek3rdwtX5KojFhPDT1edl7d6sFSXE5m8E2sbbBht BwC+AfmEyw+lkU
3G4Zss0Q5huL+tW9r3pZ9aIVORgA3AQlW+mKtX+GB8CQ56kVq/drWYbT5ec5ZUhv
X65CPi697hgdeD331kL9lnfxXgdAj8z4TPdGM76XNq0dwEBXSO TV5LHJUOztYX+s
30NpUq3xQVAJpdiYtH7BHKs2roTSiGLoy7NLRyhGZ1XZ5anZFs sOstNX8tqzntIy
WaxpDs85wX72UlO6m3BOgXDfi2xH0CsPjiBSyLO8cOVGB8Mty6 hl7juBO9yhtWOd
V69p3khwq3/kMPaOOb4Kjdr+BzmDX2xEu/JZx0uTCyFEQGTGLzqDoSz/Tt5Wy31O
z1B/bf8a7aoS/LhlaD+xq76IpuHBA+uVLxrODoyZdiECLhHNJZ7V41m0JDYxOWQ x
MTgwLWU2MTEtMTFkZi04ODBhLTEyMzEzOTBhOWNjMYixBBABAg AbBQJNIWyABYkA
AAAAAhsDAgsHAhUCAhYCAh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n
3vG36efFEd/gVIDs70x6yrTpUTWI7kRgTYEpZA==
=xcAg
-----END PGP PRIVATE KEY BLOCK-----
^Z
gpg: key 169C844F: secret key imported
gpg: key 169C844F: public key "619d1180-e611-11df-880a-1231390a9cc1" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
gpg: secret keys read: 1
gpg: secret keys imported: 1
____________
Any kind soul, please let me know what is wrong with my code and how to solve this problem. Thank you very much.
Bookmarks