I've created a prototype, in Java that creates an s/mime file, and now I need 
to convert that to the equivalent of what the "binary" switch does when using 
openssl.  The command in openssl is:

openssl smime -binary -sign -passin "pass:MyPassword" -signer cert.pem -inkey 
key.pem -in DocumentToSign.txt -out SignedDocument.der -outform DER

What I have now in Java produces a PEM formatted s/mime file.  Here is the Java 
code so fa using bouncy castle 1.4.7r:

SMIMESignedGenerator gen = new SMIMESignedGenerator();
// Note:  If I set the content transfer encoding to "binary" it only makes the 
main content binary and not the whole s/mime file.
// gen.setContentTransferEncoding("binary"); 
Store certs = new JcaCertStore(certList);
SignerInfoGenerator sig = new 
JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WithRSA", 
signKP.getPrivate(), signCert);
gen.addSignerInfoGenerator(sig);
gen.addCertificates(certs);
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props);
MimeMessage body = new MimeMessage(session);
MimeBodyPart part1 = new MimeBodyPart();                        
part1.setText(msgText); // msgText is the contents of a file to sign into an 
s/mime file.
MimeMultipart mp = gen.generate(part1);
body.setContent(mp, mp.getContentType());
body.saveChanges();
body.writeTo(System.out);  // at this point I get a PEM looking s/mime file.

What I want to do is encode the WHOLE s/mime set of bytes into binary the way 
the "binary" switch does on the "openssl smime binary" invocation does.

Can anyone provide any help here?  Is it just a matter of stripping CR and or 
LF bytes out of the file?

Bart

Reply via email to