Encrypting more than once

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Encrypting more than once

Maria Sigal
I use the same key when i encrypt several times  but it looks like that  i
need to  create

JceKeyTransRecipientInfoGenerator infoGenerator = new
JceKeyTransRecipientInfoGenerator(certificate);
            infoGenerator.setProvider(BouncyCastleProvider.PROVIDER_NAME);
            recipient = infoGenerator;

 as the number of  times i encapsulate EnvelopedData  , otherwise something
gets wrongs  with the key , with the encryption and when  i decrypt the
message i get an error

 java.lang.IllegalArgumentException: failed to construct sequence from
byte[]: DER length more than 4 bytes: 14.

Why doesn't  it  work  to pass  each time the same
JceKeyTransRecipientInfoGenerator object to the
CMSEnvelopedDataStreamGenerate  when creating encapsulated EnvelopedData  if
the certificate is the same  .





--
Sent from: http://bouncy-castle.1462172.n4.nabble.com/Bouncy-Castle-Dev-f1462173.html

Reply | Threaded
Open this post in threaded view
|

Re: Encrypting more than once

David Hook-3

The object has to hold on to the symmetric session key which is output
at the end of the generation cycle. Re-using like this will result in
one of the session keys getting lost.

Regards,

David

On 28/01/18 00:09, Maria Sigal wrote:

> I use the same key when i encrypt several times  but it looks like that  i
> need to  create
>
> JceKeyTransRecipientInfoGenerator infoGenerator = new
> JceKeyTransRecipientInfoGenerator(certificate);
>             infoGenerator.setProvider(BouncyCastleProvider.PROVIDER_NAME);
>             recipient = infoGenerator;
>
>  as the number of  times i encapsulate EnvelopedData  , otherwise something
> gets wrongs  with the key , with the encryption and when  i decrypt the
> message i get an error
>
>  java.lang.IllegalArgumentException: failed to construct sequence from
> byte[]: DER length more than 4 bytes: 14.
>
> Why doesn't  it  work  to pass  each time the same
> JceKeyTransRecipientInfoGenerator object to the
> CMSEnvelopedDataStreamGenerate  when creating encapsulated EnvelopedData  if
> the certificate is the same  .
>
>
>
>
>
> --
> Sent from: http://bouncy-castle.1462172.n4.nabble.com/Bouncy-Castle-Dev-f1462173.html
>
>