|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.smime.SMimeContent iaik.smime.CompressedContent
public class CompressedContent
This class can be used to create compressed S/MIME emails in combination with the JavaMail API (javax.mail package).
The S/MIME
(Secure/Multipurpose Internet Mail Extensions) protocol specifies
the compressed-data
content type for compressing MIME entities
by using the CMS type CompressedData
.
After preparing the MIME entity in the usual way it is packed it into a
CMS CompressedData object, wrapped by CMS ContentInfo object. Finally the
ContentInfo is put into a S/MIME entity of content type application/pkcs7-mime
with the following MIME headers:
Content-Type: application/pkcs7-mime; smime-type=compressed-data; name=smime.p7z Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=smime.p7zAfter having
created
a new CompressedContent object,
the content to be compressed has to be supplied by means of a setContent
,
setText
, or setDataHandler
method. Before actually sending the message with the compressed content, the
compression algorithm
has to be set, and
method setHeaders
shall be called for properly updating
the message headers, e.g.:
// the mail session Session = ...; // create a new MIME message and set Subject, From, To,... headers MimeMessage msg = new MimeMessage(session); ... // created a CompressedContent object CompressedContent compressed = new CompressedContent(); // supply the content, e.g.: DataHandler dh = ...; compressed.setDataHandler(dh); // set the compression algorithm to be used, e.g.: compressed.setCompressionAlgorithm((AlgorithmID)CMSAlgorithmID.zlib_compress.clone()); // update message headers compressed.setHeaders(msg); // set the CompressedContent as content of the message msg.setContent(compressed, compressed.getContentType()); // send the message Transport.send(msg);A recipient simply accesses the content of the compressed message, e.g.:
CompressedContent compressed = (CompressedContent)msg.getContent(); // get the (decompressed, original) content Object content = compressed.getContent(); ...
For more information about the JavaMail architecture, and how to handling MIME messages, consult the JavaMail specification.
For using the IAIK-CMS S/MIME library, you also will need the following packages:
iaik_jce(_full).jar
(IAIK-JCE Core Crypto Library).
iaik_eccelerate.jar
(IAIK ECC Library; if you want to use Elliptic Curve Cryptography).
mail.jar
(JavaMail API).
activation.jar
(Java Activation Framework; required for JDK versions < 1.6).
# # IAIK mailcap file entries # multipart/signed;; x-java-content-handler=iaik.smime.signed_content application/x-pkcs7-signature;; x-java-content-handler=iaik.smime.signed_content application/x-pkcs7-mime;; x-java-content-handler=iaik.smime.encrypted_content application/x-pkcs10;; x-java-content-handler=iaik.smime.pkcs10_content application/pkcs7-signature;; x-java-content-handler=iaik.smime.signed_content application/pkcs7-mime;; x-java-content-handler=iaik.smime.encrypted_content application/pkcs10;; x-java-content-handler=iaik.smime.pkcs10_contentThe content handlers are registered by copying the mailcap file into the lib directory of your JDK (
String mailcapFileName = ...; MailcapCommandMap mc = new MailcapCommandMap(mailcapFileName); CommandMap.setDefaultCommandMap(mc);For a more detailed description of mailcap handling consult the Javadoc of the Activation Framework.
When creating a new CompressedContent to be sent per default the new S/MIME content types
(application/pkcs7-mime) are used. For using the old types (application/x-pkcs7-mime) call
the static useNewContentTypes
method of the SMimeParameters
class before creating
a new CompressedContent
object, e.g.:
//switch to old content types SMimeParameters.useNewContentTypes(false); //create a SignedContent CompressedContent sc = new CompressedContent(); ...
CompressedDataStream
Constructor Summary | |
---|---|
CompressedContent()
Creates a new CompressedContent object. |
|
CompressedContent(CryptoContent cryptoContent)
Creates a new S/MIME CompressedContent object for the a content to be signed (or encrypted) and then compressed. |
|
CompressedContent(javax.activation.DataSource dataSource)
Constructs a CompressedContent object from the given data source. |
Method Summary | |
---|---|
AlgorithmID |
getCompressionAlgorithm()
Returns the compression algorithm (including any associated parameters) of this CompressedContent. |
java.io.InputStream |
getContentInputStream()
Returns an InputStream with the unparsed content. |
javax.activation.DataHandler |
getDataHandler()
Return a DataHandler holding the content. |
java.lang.String |
getSMimeType()
Returns the smime-type parameter ("compressed-data"). |
void |
setCompressionAlgorithm(AlgorithmID compressionAlgorithm)
Sets the compression algorithm to be used for content compressiom. |
void |
setHeaders(javax.mail.Part part)
Sets additional headers of the part (message) containing this CompressedContent. |
void |
writeTo(java.io.OutputStream os)
Writes this CompressedContent BER encoded to the given output stream. |
Methods inherited from class iaik.smime.SMimeContent |
---|
getContent, getContentType, getInputStream, setBlockSize, setContent, setContent, setContentContentHeaders, setContentContentTransferEncoding, setDataHandler, setText |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CompressedContent()
Use a proper setContent
, setText
, or
setDataHandler
method for supplying the
content to be compressed. Before actually sending the message with the compressed content, the
compression algorithm
has to be set, and
method setHeaders
shall be called for properly updating
the message headers, e.g.:
// the mail session Session = ...; // create a new MIME message and set Subject, From, To,... headers MimeMessage msg = new MimeMessage(session); ... // created a CompressedContent object CompressedContent compressed = new CompressedContent(); // supply the content, e.g.: DataHandler dh = ...; compressed.setDataHandler(dh); // set the compression algorithm to be used, e.g.: compressed.setCompressionAlgorithm((AlgorithmID)CMSAlgorithmID.zlib_compressed.clone()); // update message headers compressed.setHeaders(msg); // set the CompressedContent as content of the message msg.setContent(compressed, compressed.getContentType()); // send the message Transport.send(msg);The smime-tpye parameter of the Content-Type header is set to "compressed-data", and the name parameter is set to "smime.p7z".
public CompressedContent(CryptoContent cryptoContent) throws javax.mail.MessagingException
cryptoContent
- the signed (or encrypted) content to be compressed
(however it may be preferable to first compress and
then sign or encrypt)
javax.mail.MessagingException
public CompressedContent(javax.activation.DataSource dataSource) throws java.io.IOException
content handler
supplying the data source.
For more information on data handling using the
javax.activation.DataSource
for "MIME type based" data
access, see the
JavaBeans Activation Framework (JAF) specification.
dataSource
- the DataSource supplying the compressed data
java.io.IOException
- if an I/O error occurs during reading the objectMethod Detail |
---|
public void setHeaders(javax.mail.Part part)
Content-Disposition: attachment"; filename="smime.p7z" Content-Transfer-Encoding: base64It is highly recommended to call this method to set the headers above for the part containing this CompressedContent to avoid processing overhead :
MimeMessage msg = ...; CompressedContent compressed = ...; compressed.setHeaders(msg);If this method is not called, JavaMail may run method
writeTo
twice
to determine the content transfer encoding to be used.
part
- the part for which the Content-Disposition and Content-Transfer-Encoding
headers should be setpublic javax.activation.DataHandler getDataHandler() throws javax.mail.MessagingException
getDataHandler
in class SMimeContent
javax.mail.MessagingException
- if an error occurs when fetching the data handlerpublic java.io.InputStream getContentInputStream() throws java.io.IOException
Attention!This method may be called only once since a stream only
can be read once. However, if any of the content accessing methods like
getContent
or getDataHandler
is called before
calling getContentInputStream
, getContentInputStream
may be called repeadetly since in this case the content is internally kept by
means of a DataHandler.
java.io.IOException
- if an error occurs when reading the datapublic java.lang.String getSMimeType()
public void setCompressionAlgorithm(AlgorithmID compressionAlgorithm) throws java.security.NoSuchAlgorithmException
compressionAlgorithm
- the algorithm to be used for content compression
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supportedpublic AlgorithmID getCompressionAlgorithm()
public void writeTo(java.io.OutputStream os) throws java.io.IOException, javax.mail.MessagingException
java.io.IOException
- if an error occurs writing to the stream
javax.mail.MessagingException
- if an error occurs when fetching the data to be written
|
This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |