[Botan-devel] Problem with RSA Encryption/decryption

Jack Lloyd lloyd at randombit.net
Tue Jul 5 12:35:58 EDT 2005

On Tue, Jul 05, 2005 at 06:02:26PM +0200, Ruben Quintero Lores wrote:
> Hi!!
> I have the following code to encrypt/desencrypt the hash of a Diffie
> Hellmann  session  symetric  key, I use to encrypt a private RSA key
> and a public RSA key to desencrypt
> byte*    modify(bool    encryption,   RSA_PrivateKey   *aprivatekey,
> RSA_PublicKey *apublickey)
> {
>     initialize_botan();
>     if (encryption)  // encryption
>     {
>         PK_Encryptor*   rsa_enc   =   get_pk_encryptor(*aprivatekey,
> "EME1(SHA-1)");
>      SecureVector<byte> cipher =
> rsa_enc->encrypt(sessionkey.bits_of(), sizeof(sessionkey));
>      delete rsa_enc;
>      return (byte*)cipher;
>     }
>   else  //decryption
>     {
>         PK_Decryptor*    rsa_dec   =   get_pk_decryptor(*apublickey,
> "EME1(SHA-1)");
>      SecureVector<byte> cipher =
> rsa_dec->decrypt(sessionkey.bits_of(), sizeof(sessionkey));
>      delete rsa_dec;
>      return (byte*)cipher;
>     }
> }

This can't be right - it won't even compile, because you are trying to pass an
RSA_PublicKey to get_pk_decryptor, which won't work because RSA_PublicKey is
not a subclass of PK_Decrypting_Key.

>   what():  Botan: PK_Decryptor_MR_with_EME: Input is invalid
> What  happend??  Wich is the meaning of this error?? What I'll doing
> wrong??

It means the ciphertext was accidentally or intentionally modified or corrupted
between encryption and decryption, or you used the wrong key to decrypt, or
some other error - basically it means that it was not possible to return the
correct plaintext, thus there must have been an error somewhere along the way.

As a guess, are you trying to decrypt the original session key? Which is
presumably 128-256 bits of random key, rather than the RSA encrypted version of


More information about the botan-devel mailing list