The code below shows how to do public key encryption, decryption, signing and verification.
#include <QtCrypto>
#include <QCoreApplication>
#include <iostream>
#ifdef QT_STATICPLUGIN
#include "import_plugins.h"
#endif
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
std::cout << "Sorry, no PKI certificate support" << std::endl;
return 1;
}
std::cout << "Sorry, could not import Private Key" << std::endl;
return 1;
}
std::cout << "Sorry, could not import public key certificate" << std::endl;
return 1;
}
chain += pubCert;
QByteArray plainText = (argc >= 2) ? argv[1] : "What do ya want for nuthin'";
{
std::cout <<
"Error encrypting: " << msg.
errorCode() << std::endl;
return 1;
}
std::cout << plainText.data() << " encrypts to (in base 64): ";
std::cout << qPrintable( enc.
arrayToString( cipherText ) ) << std::endl;
std::cout << "Private key cannot be used to decrypt" << std::endl;
return 1;
}
std::cout << "Decryption process failed" << std::endl;
return 1;
}
std::cout << " (in base 64) decrypts to: ";
std::cout << plainTextResult.
data() << std::endl;
return 0;
}