Hi Gordon,

The followinf is taken from 5.2.1's test.cpp:

void GenerateRSAKey(unsigned int keyLength, const char *privFilename,
const char *pubFilename, const char *seed)
{
        RandomPool randPool;
        randPool.Put((byte *)seed, strlen(seed));

        RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
        HexEncoder privFile(new FileSink(privFilename));
        priv.DEREncode(privFile);
        privFile.MessageEnd();

        RSAES_OAEP_SHA_Encryptor pub(priv);
        HexEncoder pubFile(new FileSink(pubFilename));
        pub.DEREncode(pubFile);
        pubFile.MessageEnd();
}

string RSAEncryptString(const char *pubFilename, const char *seed,
const char *message)
{
        FileSource pubFile(pubFilename, true, new HexDecoder);
        RSAES_OAEP_SHA_Encryptor pub(pubFile);

        RandomPool randPool;
        randPool.Put((byte *)seed, strlen(seed));

        string result;
        StringSource(message, true, new PK_EncryptorFilter(randPool,
pub, new HexEncoder(new StringSink(result))));
        return result;
}

string RSADecryptString(const char *privFilename, const char
*ciphertext)
{
        FileSource privFile(privFilename, true, new HexDecoder);
        RSAES_OAEP_SHA_Decryptor priv(privFile);

        string result;
        StringSource(ciphertext, true, new HexDecoder(new
PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
        return result;
}

>>> [EMAIL PROTECTED] 2/8/2006 3:25 PM >>>
Hi,

I am a newbie with cryptoPP

I am trying to decrypt a string that was crypted in RSA

but it doesn't work, I have an exception that say "Invalid
ciphertext",

in my program the RSA private key was succesfully loaded, but when the

program try to decrypt the ciphertext it doesn't work

I am sure that the ciphertext is Ok, so I don't understand, I need help

please

here my source code:

 std::string Crypto::RSADecryptString( const char *privKey, const char

*ciphertext){

        //privKey is the privateKey, in hexadecimal format
   StringSource privFile(privKey, true, new HexDecoder);
   RSAES_OAEP_SHA_Decryptor priv(privFile);

          //here we try to decrypt a ciphertext, here ciphertext is in

hexadecimal format
        RandomPool randomPool;
   string result;
         StringSource(ciphertext, true, new HexDecoder(new 
PK_DecryptorFilter(randomPool, priv, new StringSink(result))));
   return result;

}

can you send me a source code who explain the encryption/decryption
method 
for RSA ?

thanks 



Reply via email to