List of usage examples for org.bouncycastle.mail.smime SMIMECompressedGenerator ZLIB
String ZLIB
To view the source code for org.bouncycastle.mail.smime SMIMECompressedGenerator ZLIB.
Click Source Link
From source file:chapter9.CompressedMailExample.java
/** * * @param args/* w ww. j av a 2s . co m*/ * @throws Exception */ public static void main(String[] args) throws Exception { //1.- Create the message we want compressed MimeBodyPart dataPart = new MimeBodyPart(); dataPart.setText("Hello World!!"); //2.- Set up the generator SMIMECompressedGenerator gen = new SMIMECompressedGenerator(); //3.- Generate the compressed message MimeBodyPart comPart = gen.generate(dataPart, SMIMECompressedGenerator.ZLIB); //4-. Create the mail message MimeMessage mail = Utils.createMimeMessage("example compressed message", comPart.getContent(), comPart.getContentType()); //5.- Create the enveloped object from the mail message SMIMECompressed compressed = new SMIMECompressed(mail); //6.- Uncompression step MimeBodyPart recoveredPart = SMIMEUtil.toMimeBodyPart(compressed.getContent()); //7.- Content display step System.out.print("Content: "); System.out.println(recoveredPart.getContent()); }
From source file:com.zotoh.crypto.CryptoUte.java
License:Open Source License
/** * @param contentType// w ww .ja v a 2s. com * @param msg * @return * @throws IOException * @throws MessagingException * @throws GeneralSecurityException */ public static MimeBodyPart compressContent(String contentType, StreamData msg) throws IOException, MessagingException, GeneralSecurityException { tstEStrArg("content-type", contentType); tstObjArg("input-content", msg); SMIMECompressedGenerator gen = new SMIMECompressedGenerator(); MimeBodyPart bp = new MimeBodyPart(); SmDataSource ds; if (msg.isDiskFile()) { ds = new SmDataSource(msg.getFileRef(), contentType); } else { ds = new SmDataSource(msg.getBytes(), contentType); } bp.setDataHandler(new DataHandler(ds)); try { return gen.generate(bp, SMIMECompressedGenerator.ZLIB); } catch (SMIMEException e) { throw new GeneralSecurityException(e); } }
From source file:com.zotoh.crypto.CryptoUte.java
License:Open Source License
/** * @param msg//from w w w. jav a2 s. c o m * @return * @throws GeneralSecurityException */ public static MimeBodyPart compressContent(MimeMessage msg) throws GeneralSecurityException { tstObjArg("mime-message", msg); try { return new SMIMECompressedGenerator().generate(msg, SMIMECompressedGenerator.ZLIB); } catch (SMIMEException e) { throw new GeneralSecurityException(e); } }
From source file:com.zotoh.crypto.CryptoUte.java
License:Open Source License
/** * @param cType//from w w w . j a v a2 s .c om * @param cte * @param contentLoc * @param cid * @param msg * @return * @throws MessagingException * @throws IOException * @throws GeneralSecurityException */ public static MimeBodyPart compressContent(String cType, String cte, String contentLoc, String cid, StreamData msg) throws MessagingException, IOException, GeneralSecurityException { tstEStrArg("content-type", cType); tstEStrArg("content-id", cid); tstObjArg("input-content", msg); SMIMECompressedGenerator gen = new SMIMECompressedGenerator(); MimeBodyPart bp = new MimeBodyPart(); SmDataSource ds; if (msg.isDiskFile()) { ds = new SmDataSource(msg.getFileRef(), cType); } else { ds = new SmDataSource(msg.getBytes(), cType); } if (!isEmpty(contentLoc)) { bp.setHeader("content-location", contentLoc); } try { bp.setHeader("content-id", cid); bp.setDataHandler(new DataHandler(ds)); bp = gen.generate(bp, SMIMECompressedGenerator.ZLIB); } catch (SMIMEException e) { throw new GeneralSecurityException(e); } if (true) { int pos = cid.lastIndexOf(">"); if (pos >= 0) { cid = cid.substring(0, pos) + "--z>"; } else { cid = cid + "--z"; } } if (!isEmpty(contentLoc)) { bp.setHeader("content-location", contentLoc); } bp.setHeader("content-id", cid); // always base64 cte = "base64"; if (!isEmpty(cte)) { bp.setHeader("content-transfer-encoding", cte); } return bp; }
From source file:hk.hku.cecid.piazza.commons.security.SMimeMessage.java
License:Open Source License
/** * Compresses the encapsulated MIME body part. * /*from w ww . j a va 2 s . c o m*/ * @return an S/MIME message encapsulating the compressed MIME body part. * @throws SMimeException if unable to compress the body part. */ public SMimeMessage compress() throws SMimeException { try { try { setDefaults(); /* Create the generator for creating an smime/compressed body part */ SMIMECompressedGenerator compressor = new SMIMECompressedGenerator(); compressor.setContentTransferEncoding(getContentTransferEncoding()); /* compress the body part */ MimeBodyPart compressedPart = compressor.generate(bodyPart, SMIMECompressedGenerator.ZLIB); return new SMimeMessage(compressedPart, this); } catch (org.bouncycastle.mail.smime.SMIMEException ex) { throw new SMimeException(ex.getMessage(), ex.getUnderlyingException()); } } catch (Exception e) { throw new SMimeException("Unable to compress body part", e); } }
From source file:io.aos.crypto.spl09.CompressedMailExample.java
License:Apache License
public static void main(String args[]) throws Exception { // create the message we want compressed MimeBodyPart dataPart = new MimeBodyPart(); dataPart.setText("Hello world!"); // set up the generator SMIMECompressedGenerator gen = new SMIMECompressedGenerator(); // generate the compressed message MimeBodyPart comPart = gen.generate(dataPart, SMIMECompressedGenerator.ZLIB); // create the mail message MimeMessage mail = Utils.createMimeMessage("example compressed message", comPart.getContent(), comPart.getContentType());// w ww . j a v a2 s.c o m // create the enveloped object from the mail message SMIMECompressed compressed = new SMIMECompressed(mail); // uncompression step MimeBodyPart recoveredPart = SMIMEUtil.toMimeBodyPart(compressed.getContent()); // content display step System.out.print("Content: "); System.out.println(recoveredPart.getContent()); }
From source file:mitm.common.security.smime.SMIMEBuilderImpl.java
License:Open Source License
@Override public void compress() throws SMIMEBuilderException { try {//w w w .j av a 2s. c om bodyPart = compressedGenerator.generate(bodyPart, SMIMECompressedGenerator.ZLIB); /* * We will use the deprecated content-type if required. We do this by changing the content-type * header. I wish I could specify the content-type for the envelopedGenerator but that's not * possible without completely reimplemening envelopedGenerator. This is a workaround until * BC allows me to set the content-type */ if (useDeprecatedContentTypes) { bodyPart.setHeader("Content-Type", SMIMEHeader.DEPRECATED_COMPRESSED_CONTENT_TYPE); } compressedGenerator = new PrivateSMIMECompressedGenerator(); } catch (SMIMEException e) { throw new SMIMEBuilderException(e); } catch (MessagingException e) { throw new SMIMEBuilderException(e); } }