Unable to get the encrypted sign in Outlood and Thunderbird

I write a program that encrypt an email with text content and attached file.

When the email is received:

- On MS Outlood 2003: There's no content in the email and have no ecrypted sign.

- On Thunder bird version 2.0 : I can see the content and the attachment file but still have no ecrypted sign in the email. (Note: if i send this mail to user that have no trusted certificate installed than he can't read the email).

Anybody can help me what's going wrong ?

Here 's my program:

MailCrypto mailCrypto=new MailCrypto();

MimeBodyPart bp=new MimeBodyPart();

bp.setHeader("Content-Type","text/plain");

bp.setContent("Hello World!!!","text/plain; charset=\"ISO-8859-1\"");

MimeBodyPart bp2=new MimeBodyPart();

FileDataSource fileAttachment =new FileDataSource("C:\\csb.log");

DataHandler dh =new DataHandler(fileAttachment);

bp2.setDataHandler(dh);

//bp2.setDisposition(Message.ATTACHMENT);

bp2.setFileName(fileAttachment.getName());

bp2.setHeader("Content-Type","application/log");

KeyStore credentials=getKeyStore("123456","C:\\keystore_viettq.p12");

Certificate[]chain = credentials.getCertificateChain("mycert");

X509Certificate cert = (X509Certificate)chain[0];

// set up the generator

SMIMEEnvelopedGenerator gen =new SMIMEEnvelopedGenerator();

gen.addKeyTransRecipient(cert);

// Create Base Message

MimeMessage baseMsg=new MimeMessage((Session)null);

Multipart multipart =new MimeMultipart();

multipart.addBodyPart(bp1);

multipart.addBodyPart(bp2);

Address fromUser =new InternetAddress("\"Trinh Quang Viet\"<trinh.quang.viet@vsi-international.com>");

Address toUser =new InternetAddress("trinh.quang.viet@vsi-international.com");

baseMsg.setHeader("Content-Type","multipart/mixed");

baseMsg.setFrom(fromUser);

baseMsg.setRecipient(Message.RecipientType.TO, toUser);

baseMsg.setSubject("Example Encrypted Message");

baseMsg.setContent(multipart);

baseMsg.saveChanges();

//End Test part

// generate the enveloped message

MimeBodyPart encryptedPart = gen.generate(baseMsg, SMIMEEnvelopedGenerator.RC2_CBC,"BC");

Multipart finalMutiPart =new MimeMultipart();

finalMutiPart.addBodyPart(encryptedPart);

Properties props =new Properties();

props.put("mail.smtp.host","mail.vsi-international.com");

props.put("mail.smtp.auth","true");

props.put("mail.debug","true");

props.put("mail.smtp.user","trinh.quang.viet@vsi-international.com");

props.put("mail.smtp.password","xxxxxxxx");

props.put("mail.smtp.port","25");

Authenticator auth =new SMTPAuthenticator();

Session session = Session.getDefaultInstance(props, auth);

session.setDebug(true);

MimeMessage theEMail =new MimeMessage(session);

//theEMail.setHeader("Content-Type", "application/x-pkcs7-mime");

theEMail.setHeader("Content-Type","multipart/mixed");

theEMail.setFrom(fromUser);

theEMail.setRecipient(Message.RecipientType.TO, toUser);

theEMail.setSubject("Example Encrypted Message");

theEMail.setContent(finalMutiPart);

theEMail.saveChanges();

Transport.send(theEmail);

Thanks

[4822 byte] By [purplenovaa] at [2007-11-27 8:41:15]
# 1
For some reasons, OE and Thunder Bird can't display the encrypted sign. I tried another way with Mail-Crypto API and it works well.Thanks
purplenovaa at 2007-7-12 20:40:07 > top of Java-index,Security,Cryptography...