Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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!!!!
Posted
Comments
Richard MacCutchan 26-Jan-14 12:09pm    
You cannot decrypt the encrypted string using a different key.
pasztorpisti 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

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:
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.

—SA
 
Share this answer
 
v2
Comments
pasztorpisti 26-Jan-14 17:26pm    
+5
Sergey Alexandrovich Kryukov 26-Jan-14 17:53pm    
Thank you.
—SA
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900