1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <botan/auto_rng.h> #include <botan/data_src.h> #include <botan/pubkey.h> #include <botan/x509_key.h>
bool encryptByRSA(const QString ¶mDataSource, QByteArray ¶mDataDest, const QString &pubKey) { try { Botan::AutoSeeded_RNG rng; Botan::DataSource_Memory pem(pubKey.toStdString()); std::unique_ptr<Botan::X509_PublicKey> temp_pub(Botan::X509::load_key(pem)); Botan::PK_Encryptor_EME enc(*temp_pub, rng, "EME-PKCS1-v1_5"); std::vector<uint8_t> en = enc.encrypt((unsigned char *) paramDataSource.toUtf8().data(), paramDataSource.toUtf8().size(), rng); paramDataDest = QByteArray::fromRawData((char *) &en[0], en.size()).toBase64(); return true; } catch (std::runtime_error &e) { qWarning() << e.what(); return false; } }
|