*public-key cryptography*works. The key is never an arbitrary piece of data. Even if it was so, isn't the following obvious: if one key is arbitrary, the second of the keys in the key pair is somehow related to the other key? :-)

First of all, you really need to understand how public-key cryptography works. Please see:

http://en.wikipedia.org/wiki/Public-key_cryptography[^] (very clear explanation, must-read for every developer),

http://en.wikipedia.org/wiki/RSA_%28algorithm%29[^].

As to Crypto++ implementation, the documentation is quite easy to find:

http://www.cryptopp.com/wiki/RSA_Cryptography#Keys[^],

http://www.cryptopp.com/wiki/Main_Page[^].

The final note: if you say that this simple problem "cost me too much time", this is troublesome sign, but all you need it to keep learning and getting experience. All such problems should be resolved quickly, as they are reduced to just using some very usual API, not creating something new.