The code below shows some of the capabilities for how to use RSA. This example also shows how to export and import a key to a file, using PEM encoding.
#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 << "RSA not supported!\n";
else {
std::cout << "Failed to make private RSA key" << std::endl;
return 1;
}
std::cout << "Error: this kind of key cannot encrypt" << std::endl;
return 1;
}
std::cout << "Error encrypting" << std::endl;
return 1;
}
std::cout <<
"\"" << arg.
data() <<
"\" encrypted with RSA is \"";
std::cout << qPrintable(rstr) << "\"" << std::endl;
seckey.
toPEMFile(
"keyprivate.pem", passPhrase);
passPhrase,
&conversionResult);
std::cout << "Private key read failed" << std::endl;
}
std::cout << "Error decrypting.\n";
return 1;
}
std::cout << "\"" << qPrintable(rstr) << "\" decrypted with RSA is \"";
std::cout << decrypt.
data() <<
"\"" << std::endl;
std::cout << "Error: this kind of key cannot sign" << std::endl;
return 1;
}
std::cout <<
"Signature for \"" << arg.
data() <<
"\" using RSA, is ";
std::cout << "\"" << qPrintable( rstr ) << "\"" << std::endl;
std::cout << "Signature is valid" << std::endl;
} else {
std::cout << "Bad signature" << std::endl;
}
}
std::cout << "Signature is valid" << std::endl;
} else {
std::cout << "Signature could not be verified" << std::endl;
}
}
return 0;
}