The code below shows how to load a private key from a PEM format file, including handling any requirement for a passphrase. This is done using the QCA::KeyLoader class.
#include <QtCrypto>
#include <QCoreApplication>
#include <QTimer>
#include <stdio.h>
#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif
class PassphraseHandler:
public QObject
{
Q_OBJECT
public:
{
connect(&handler, SIGNAL(eventReady(
int,
const QCA::Event &)),
}
private slots:
void eh_eventReady(
int id,
const QCA::Event &event)
{
{
}
else
}
};
{
Q_OBJECT
public:
QString str;
App()
{
connect(&keyLoader, SIGNAL(finished()), SLOT(kl_finished()));
}
public slots:
void start()
{
}
signals:
void quit();
private slots:
void kl_finished()
{
{
printf(
"Loaded successfully. Bits: %d\n", key.
bitSize());
}
else
printf("Unable to load.\n");
emit quit();
}
};
int main(int argc, char **argv)
{
QCoreApplication qapp(argc, argv);
if(argc < 2)
{
printf("usage: keyloader [privatekey.pem]\n");
return 0;
}
PassphraseHandler passphraseHandler;
App app;
app.str = argv[1];
QObject::connect(&app, SIGNAL(quit()), &qapp, SLOT(quit()));
QTimer::singleShot(0, &app, SLOT(start()));
qapp.exec();
return 0;
}
#include "keyloader.moc"