I have seen example of Cryptopp, there is GenerateRSAKey function which 
generate a public and private key to file, but I want to generate it to 
memory. Thus I have change the source code from 

HexEncoder privFile(new FileSink(privFilename));
HexEncoder pubFile(new FileSink(pubFilename));
--->
HexEncoder privString(new StringSink(privResult));
HexEncoder pubString(new StringSink(pubResult));

Is there right? 

Then I use this pair of key to encrypt and decrypt a string but it fatal 
error 
My encrypt and decrypt code:

char* CRSAService::EncryptString(const char *pszPublicKey, char *pszSeeds, 
char *pszMessage)
{
char *pszResult;
RandomPool randPool;
randPool.IncorporateEntropy((byte *)pszSeeds, strlen(pszSeeds));

StringSource pubString(pszPublicKey, true, new HexDecoder);
RSAES_OAEP_SHA_Encryptor pub(pubString);

string szResult;

StringSource(pszMessage, true, new PK_EncryptorFilter(randPool, pub, new 
HexEncoder(new StringSink(szResult))));

pszResult = new char[szResult.size() + 1];
copy(szResult.begin(), szResult.end(), pszResult);
pszResult[szResult.size()] = '\0';

return pszResult;
}

char* CRSAService::DecryptString(const char *pszPrivateKey, char 
*pszCipherText)
{
char *pszResult;
StringSource privString(pszPrivateKey, true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor priv(privString);

string szResult;
StringSource(pszCipherText, true, new HexDecoder(new 
PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(szResult))));

pszResult = new char[szResult.size() + 1];
copy(szResult.begin(), szResult.end(), pszResult);
pszResult[szResult.size()] = '\0';

return pszResult;
}

Is there something wrong?

Cam Vi

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