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
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;
}
>>> gordon.f...@wanadoo.fr 2/8/2006 3:25 PM >>>
but I have already test this code example, it's this piece of code:
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;
}
but this code doesn't work with my private key and ciphertext ,
this private key and ciphertext was generated by a Java application ( with
JCE package cryptography ), it seems that CryptoPP have maybe a problem if
privatekey and ciphertext are created by Java applications ?
you can help me by this way: I send you with this mail 2 files that
represent
the privateKey and the ciphertext in binary format ( pure format, not text
format )
can you tell me if you can decrypt the ciphertext with cryptoPP ?
thanks
"Jeffrey Walton" <DIGI...@aacounty.org> a écrit dans le message de news:
s3ea10...@ACGWMTA02.aacounty.org...
[...]
> 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;
> }
>
> but this code doesn't work with my private key and ciphertext ,
[...]
> you can help me by this way: I send you with this mail 2 files that
> represent
> the privateKey and the ciphertext in binary format ( pure format, not text
> format )
If they are raw, binary data, you should not use HexDecoder. But if I do
int main() {
FileSource privFile( "privatekey.bin", true, 0 );
RSAES_OAEP_SHA_Decryptor priv( privFile );
std::string result;
RandomPool randPool;
FileSource ciphertext(
"ciphertext.bin",
true,
new PK_DecryptorFilter( randPool, priv, new StringSink( result ) )
);
std::cout << '[' << result << ']';
return 0;
}
I also get 'invalid ciphertext', so it seems one of the files are
corrupted, maybe CR/LF problems? Try using standard hex encodings to
make sure there are no such problems.
Cheers,
--
Jens Peter Secher
_DD6A 05B0 174E BFB2 D4D9 B52E 0EE5 978A FE63 E8A1 jpsecher gmail com_
thanks for your answer,
maybe the problem is a bad RSA encryption in my Java Application or a non
standard RSA encryption ?
I will try standard hex encoder in the java program for extracting the
ciphertext
"Jens Peter Secher" <jpse...@diku.dk> a écrit dans le message de news:
c4f47b5b0602090201i50b...@mail.gmail.com...