[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bouncycastle-crypto-dev
Subject:    RE: [dev-crypto] Multipart mail encryption
From:       David Hook <dgh () lockboxlabs ! com>
Date:       2010-02-15 0:00:00
Message-ID: 1266192000.3347.29.camel () echidna
[Download RAW message or body]


There's a few ways of doing it all of which are okay (in terms of
dealing with the JavaMail API). What you're doing looks fine.

As an aside, ordinarily this mainly comes up in respect to sending a
encrypted signed message - in this case it's also important to encrypt
the multipart you get from signing, not to try signing an encrypted body
part.

Regards,

David


On Sun, 2010-02-14 at 23:37 +0000, Johan Hertz wrote:
> Thanks David, could I just ask you if the way I am doing it is the recommended way, \
> or if there is another that is preferable? 
> Regards
> Johan
> 
> -----Original Message-----
> From: David Hook [mailto:dgh@lockboxlabs.com] 
> Sent: 14 February 2010 23:28
> To: dev-crypto@bouncycastle.org
> Subject: RE: [dev-crypto] Multipart mail encryption
> 
> 
> There are also examples in org.bouncycastle.mail.smime.examples
> 
> Regards,
> 
> David
> 
> On Sat, 2010-02-13 at 18:12 +0000, Johan Hertz wrote:
> > Hi,
> > 
> > 
> > 
> > I have manage to find the solution, so if anyone else has this problem
> > this is what I did.
> > 
> > 
> > 
> > Wrap the multipart inside another body part and then encrypt that body
> > part.
> > 
> > 
> > 
> > In code it would look something like this
> > 
> > 
> > 
> > //Create the holder
> > 
> > MimeMultipart holder = new
> > MimeMultipart();                                            
> > 
> > 
> > 
> > //Create the body
> > 
> > MimeBodyPart body = new MimeBodyPart();
> > 
> > body.setContent(html, "text/html");
> > 
> > holder.addBodyPart(body);               
> > 
> > 
> > 
> > //Create the attachment part
> > 
> > MimeBodyPart attachment = new
> > MimeBodyPart();                                    
> > 
> > attachment.setDataHandler(new DataHandler(attachmentData));
> > 
> > attachment.setFileName("myfile.zip");
> > 
> > holder.addBodyPart(attachment);    
> > 
> > 
> > 
> > //Create the message wrapper
> > 
> > MimeBodyPart wrapper = new MimeBodyPart();         
> > 
> > 
> > 
> > //Set the holder to the wrapper
> > 
> > wrapper.setContent(holder);
> > 
> > 
> > 
> > //Create the generator
> > 
> > SMIMEEnvelopedGenerator generator = createGenerator(pkcs12Path,
> > pkcs12Password);
> > 
> > 
> > 
> > //Encrypt the wrapper
> > 
> > MimeBodyPart encrypted =  generator.generate(wrapper,
> > SMIMEEnvelopedGenerator.RC2_CBC, "BC");
> > 
> > 
> > 
> > //Go on to send the message
> > 
> > 
> > 
> > /Regards
> > 
> > Johan
> > 
> > 
> > 
> > From: Johan Hertz [mailto:johan.hertz@consensyssolutions.com] 
> > Sent: 11 February 2010 18:37
> > To: dev-crypto@bouncycastle.org
> > Subject: [dev-crypto] Multipart mail encryption
> > 
> > 
> > 
> > 
> > Hi,
> > 
> > 
> > 
> > I have looked in the archive and it seems like some people have asked
> > this already but I can't find any answers to it.
> > 
> > 
> > 
> > Is it possible to encrypt a mail with multipart in it? And if so were
> > how is it done?
> > 
> > 
> > 
> > I'm sorry if I am missing something obvious.
> > 
> > 
> > 
> > 
> > 
> > Regards
> > 
> > Johan
> > 
> > 
> > 
> > 
> 
> 
> 
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic