QCA
keyloader.cpp
The code below shows how to load a private key from a PEM format file, including handling any requirement for a passphrase.
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.
/*
Copyright (C) 2007 Justin Karneges <justin@affinix.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// QtCrypto has the declarations for all of QCA
#include <QtCrypto>
#include <QCoreApplication>
#include <QFile>
#include <QTimer>
#include <cstdio>
#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif
{
public:
QCA::EventHandler handler;
{
handler.start();
}
{
QCA::SecureArray pass;
QCA::ConsolePrompt prompt;
prompt.waitForFinished();
pass = prompt.result();
} else
}
};
{
public:
QCA::KeyLoader keyLoader;
QString str;
App()
{
}
public Q_SLOTS:
void start()
{
keyLoader.loadPrivateKeyFromPEMFile(str);
}
void quit();
private Q_SLOTS:
void kl_finished()
{
} 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;
QTimer::singleShot(0, &app, &App::start);
qapp.exec();
return 0;
}
#include "keyloader.moc"
void getHidden(const QString &promptStr)
Allow the user to enter data without it being echo'd to the terminal.
Interface class for password / passphrase / PIN and token handlers.
Definition qca_core.h:1579
void submitPassword(int id, const SecureArray &password)
function to call to return the user provided password, passphrase or PIN.
void eventReady(int id, const QCA::Event &context)
signal emitted when an Event requires attention.
void reject(int id)
function to call to indicate that the user declined to provide a password, passphrase,...
void start()
mandatory function to call after connecting the signal to a slot in your application specific passwor...
void loadPrivateKeyFromPEMFile(const QString &fileName)
Initiate an asynchronous loading of a PrivateKey from a PEM format file.
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
void quit()
QString decodeName(const QByteArray &localFileName)
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
QObject * parent() const const
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:47:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:47:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.