I email responded but it looks like that didn't go through so first of all 
thank you for answering my questions so fast! I can't wait to contribute 
back to this project and just in case anyone finds this on a search engine 
later here is what my code ended up looking like after Jeffry's great 
advice:

std::string Account::encryptData(const char *pubKeyPath, std::string data)
{
    // Load the public key (encryptor)
    CryptoPP::FileSource pubFile(pubKeyPath, true, new 
CryptoPP::HexDecoder);
    CryptoPP::RSAES_OAEP_SHA_Encryptor encryptor(pubFile);
    encryptor.AccessKey().Load(pubFile);

    // Check that message is short enough for keysize (must be shorter than 
key)
    if (data.size() > encryptor.FixedMaxPlaintextLength()) {
        std::cout << "[ANDataStore] Cannot encrypt string, it is too 
long\n";
        return "";
    }

    // Todo: add entropy?
    CryptoPP::AutoSeededRandomPool rng;

    // If the key is valid, encrypt the data
    if (encryptor.AccessKey().Validate(randPool, 3)) {
        std::string result;
        CryptoPP::StringSource(data, true,
                               new CryptoPP::PK_EncryptorFilter(rng, 
encryptor,
                               new CryptoPP::HexEncoder(
                               new CryptoPP::StringSink(result))));

        std::cout << "[aAccount]: data has been encrypted\n";
        return result;
    } else {
        std::cout << "[aAccount]: Public key validation failed!\n";
        return "";
    }
}

You definitely shouldn't copy paste my code but maybe that'll help someone 
else out as well :) Thanks again! ~Patrick

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to