Click here to Skip to main content
14,644,614 members
Rate this:
Please Sign up or sign in to vote.
See more:
Has anyone know how to encrypt string with crypto++ rsa?The crypto++ sample has just encrpt file,I want to encrypt a string with custom fix public key and private key.
for example like this:

string publicKey ="abc";
string privateKey = "123";
string message = "text to encrypt";
string encyptedString = encypt(publicKey, message);

decrypt(privateKey, encyptedString)

The problem cost me too much time,help!!!!
Richard MacCutchan 26-Jan-14 12:09pm
You cannot decrypt the encrypted string using a different key.
xenotron 26-Jan-14 17:24pm
EDIT: sorry, just realized that the keys here are arbitrarily specified pieces of text. What you say is right but you should mention that the keys must be "specially forged".

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

This is not how RSA works, and not how 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:[^] (very clear explanation, must-read for every developer),[^].

As to Crypto++ implementation, the documentation is quite easy to find:[^],[^].

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.

xenotron 26-Jan-14 17:26pm
Sergey Alexandrovich Kryukov 26-Jan-14 17:53pm
Thank you.
CmMac 27-Jan-14 1:51am
I know the rsa Algorithm,but don't know how to use Crypt++ API,example:how to load PrivateKey from an string not from FileSource?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100