[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iaik-jce] encrypt with RSA twice



Pedro Duarte wrote:
> 
> Hello to all,
> 
> When I try to ENCRYPT  the same data twice using two keys RSA...
> 
> Example:
> 
>     -- keyPR and keyPu are a key par, and key2PR and key2Pu  are another
> key par
> 
>      RSACipher.init(Cipher.ENCRYPT_MODE,keyPR);
> 
>      byte a[] =  desCipher.doFinal("hello to all".getBytes());
> 
>      RSACipher2.init(Cipher.ENCRYPT_MODE,key2PU);
> 
>     byte c[] =  desCipher.doFinal(a); *
> 
> On second *  iteration appears this error::
>     javax.crypto.BadPaddingException: Padding String must be at least 8
> octets long!
>         at iaik.pkcs.pkcs1.RSACipher.b(Unknown Source)
>         at iaik.pkcs.pkcs1.RSACipher.engineDoFinal(Unknown Source)
>         at javax.crypto.Cipher.doFinal(Unknown Source)
> 
> Why isn't  ENCRYPT the same data twice?

RSA with PKCS1 (1.5) padding requires that the data to be encrypted
is at least 11 bytes shorter than the size in bytes of the modulus.
This is required as PKCS1 padding adds a minumum 11 bytes to the data
before encryption (8 of these 11 bytes are padding).

bernard.
--
Mailinglist-archive at http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content: UNSUBSCRIBE iaik-jce