25#include <QCoreApplication>
29#include "import_plugins.h"
32int main(
int argc,
char **argv)
42 qWarning() <<
"Sorry, no PKI certificate support";
49 if (pubCert.isNull()) {
50 qWarning() <<
"Sorry, could not import public key certificate";
62 qWarning() <<
"Sorry, no CMS support";
67 msg.setRecipient(secMsgKey);
70 QByteArray plainText = (argc >= 2) ? argv[1] :
"What do ya want for nuthin'";
74 msg.update(plainText);
77 msg.waitForFinished(1000);
81 qWarning() <<
"Error encrypting: " << msg.errorCode();
88 qDebug() <<
"'" << plainText.
data() <<
"' encrypts to (in base 64): ";
90 qDebug() <<
"Message uses" << msg.hashName() <<
"hashing algorithm";
101 qWarning() <<
"Sorry, could not import Private Key";
110 privKeyList += secMsgKey2;
122 msg2.update(cipherText);
126 msg2.waitForFinished(1000);
129 if (!msg2.success()) {
130 qWarning() <<
"Error encrypting: " << msg2.errorCode();
136 qDebug() << enc.
arrayToString(cipherText) <<
" (in base 64) decrypts to: " << plainTextResult.
data();
138 if (msg2.wasSigned()) {
139 qDebug() <<
"Message was signed at " << msg2.signer().timestamp();
141 qDebug() <<
"Message was not signed";
144 qDebug() <<
"Message used" << msg2.hashName() <<
"hashing algorithm";
153 signing.setSigners(privKeyList);
156 signing.update(text);
160 signing.waitForFinished(1000);
163 if (!signing.success()) {
164 qWarning() <<
"Error signing: " << signing.errorCode();
171 qDebug() <<
"'" << text.
data() <<
"', signature (converted to base 64), is: ";
173 qDebug() <<
"Message uses" << signing.hashName() <<
"hashing algorithm";
181 verifying.startVerify(signature);
182 verifying.update(text);
185 verifying.waitForFinished(1000);
188 if (!verifying.success()) {
189 qWarning() <<
"Error verifying: " << verifying.errorCode();
194 sign = verifying.signer();
197 if (verifying.verifySuccess()) {
198 qDebug() <<
"Message verified";
200 qDebug() <<
"Message failed to verify:" << verifying.errorCode();
Base64 encoding / decoding
Cryptographic Message Syntax messaging system.
void setPrivateKeys(const SecureMessageKeyList &keys)
Set the private keys to use for the messages built using this CMS object.
A chain of related Certificates.
Public Key (X.509) certificate.
Convenience method for initialising and cleaning up QCA.
static PrivateKey fromPEMFile(const QString &fileName, const SecureArray &passphrase=SecureArray(), ConvertResult *result=nullptr, const QString &provider=QString())
Import the key in Privacy Enhanced Mail (PEM) format from a file.
char * data()
Pointer to the data in the secure array.
Key for SecureMessage system.
void setX509PrivateKey(const PrivateKey &k)
Set the private key part of this X.509 key.
void setX509CertificateChain(const CertificateChain &c)
Set the public key part of this X.509 key.
Class representing a secure message.
@ Detached
the signature is detached
QString arrayToString(const MemoryRegion &a)
Process an array in the "forward" direction, returning a QString.
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
QCA_EXPORT bool isSupported(const char *features, const QString &provider=QString())
Test if a capability (algorithm) is available.
ConvertResult
Return value from a format conversion.
@ ConvertGood
Conversion succeeded, results should be valid.