@Override
public void writeTo(SignedOutput out, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException
{
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);
mp.writeTo(os);
}