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 <QFile>
#include <QTimer>
#include <cstdio>
#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif
class PassphraseHandler:
public QObject {
Q_OBJECT
public:
{
}
private Q_SLOTS:
void eh_eventReady(
int id,
const QCA::Event &event)
{
{
prompt.
getHidden(QStringLiteral(
"Passphrase"));
}
else
}
};
{
Q_OBJECT
public:
QString str;
App()
{
}
public Q_SLOTS:
void start()
{
}
Q_SIGNALS:
void quit();
private Q_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 = QFile::decodeName(argv[1]);
QObject::connect(&app, &App::quit, &qapp, QCoreApplication::quit);
QTimer::singleShot(0, &app, &App::start);
qapp.exec();
return 0;
}
#include "keyloader.moc"