{
try
{
SMIMESignedGenerator gen = new SMIMESignedGenerator();
SignerInfoGenerator signer = new JcaSimpleSignerInfoGeneratorBuilder().setProvider("BC").build("SHA1WITHRSA", out.getPrivateKey(), out.getCertificate());
gen.addSignerInfoGenerator(signer);
MimeMultipart mp = gen.generate(EnvelopedWriter.createBodyPart(providers, out));
String contentType = mp.getContentType();
contentType = contentType.replace("\r\n", "").replace("\t", " ");
headers.putSingle("Content-Type", contentType);