Encrypt a symmetric AES key with RSA in Crypto++

Viewed 2044

I'm trying to exchange an AES key between two parts.The AES key would be encrypted with receiver's RSA publicKey and then written to a file.

I'm using Crypto++ library,and here is the beginning of my program:

//generate key pair
CryptoPP::AutoSeededRandomPool rng;
CryptoPP::RSAES_OAEP_SHA_Decryptor priv(rng, 4096);

RSA::PrivateKey privateKey(params);
RSA::PublicKey publicKey(params);

//generate aes key (256bits)
SecByteBlock key(AES::MAX_KEYLENGTH);
rnd.GenerateBlock(key, key.size());

(You will recognize Crypto++ wiki example)

Then I start the encryption routine:

CryptoPP::SecByteBlock cipher(CryptoPP::AES::MAX_KEYLENGTH), decrypted_data(CryptoPP::AES::MAX_KEYLENGTH);

CryptoPP::RSAES_OAEP_SHA_Encryptor e(publicKey);

I don't know which one to use: CryptoPP:: ArraySource or CryptoPP::StringSource?

1 Answers
Related