Answer the question
In order to leave comments, you need to log in
C++ Crypto++ RSA Encryption?
#include <cryptopp/modes.h>
#include <cryptopp/osrng.h>
#include <cryptopp/rsa.h>
#include <cryptopp/sha.h>
class MyClass
{
CryptoPP::AutoSeededRandomPool rng;
CryptoPP::RSA::PrivateKey privateKey;
CryptoPP::RSA::PublicKey publicKey;
public:
MyClass()
{
CryptoPP::RSAES_OAEP_SHA_Decryptor priv( rng, 4096 );
CryptoPP::RSAES_OAEP_SHA_Decryptor pri( rng, 2048 );
CryptoPP::InvertibleRSAFunction params;
params.GenerateRandomWithKeySize( rng, 1536 );
privateKey = CryptoPP::RSA::PrivateKey(params);
publicKey = CryptoPP::RSA::PublicKey(params);
}
QString encrypt(QString data)
{
std::string plaintext = data.trimmed().toStdString();
std::string encryptedText;
CryptoPP::RSAES_OAEP_SHA_Encryptor e( publicKey );
CryptoPP::StringSource( plaintext, true, new CryptoPP::PK_EncryptorFilter( rng, e, new CryptoPP::StringSink( encryptedText )));
return QString::fromStdString(encryptedText);
}
QString decrypt(QString encryptData)
{
std::string encryptedText = encryptedData.toStdString();
std::string decryptedtext;
CryptoPP::RSAES_OAEP_SHA_Decryptor d( privateKey );
CryptoPP::StringSource( encryptedText, true, new CryptoPP::PK_DecryptorFilter( rng, d, new CryptoPP::StringSink( decryptedtext )));
return QString::fromStdString(decryptedtext);
}
};
terminate called after throwing an instance of 'CryptoPP::InvalidArgument'
what(): RSA/OAEP-MGF1(SHA-1): ciphertext length of 386 doesn't match the required length of 192 for this key
Answer the question
In order to leave comments, you need to log in
You can do without CryptoPP and use OpenSSL, here is an example https://github.com/JulyIghor/QtBitcoinTrader/blob/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question