IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

demo.smime.basic
Class SMimeSendDemo

java.lang.Object
  extended by demo.smime.basic.SMimeSendDemo

public class SMimeSendDemo
extends java.lang.Object

This class demonstrates the usage of the IAIK S/MIME implementation for sending signed and/or encryped emails based on the JavaMail API.

To run this demo the following packages are required:

Usage:
 SMimeSend [-H host] [-S sender name] [-F (From) sender address] [-T (To) recipient address]
 
Example:
 SMimeSend -H mailhost -S \"John SMime\" -F smimetest@iaik.tugraz.at -T smimetest@iaik.tugraz.at
 
By default this demo used "mailhost" as host, "John SMime" as sender name, and "smimetest@iaik.tugraz.at" as sender and also as recipient mail address. "smimetest@iaik.tugraz.at" is also the email address contained in the demo certificates. Although you should specify other email addresses to send the test messages to yourself, be aware that the certificate email check may fail on the receiving side (SMimeShowDemo).

See Also:
EncryptedContent, SignedContent

Constructor Summary
SMimeSendDemo()
          Default constructor.
 
Method Summary
 javax.mail.Message createCertsOnlyMessage(javax.mail.Session session)
          Creates a certs-only message.
 javax.mail.Message createCertsOnlyMultiPartMessage(javax.mail.Session session)
          Creates a certs-only message where the certificate list is transferred as attachment.
 javax.mail.Message createEncryptedMessage(javax.mail.Session session, iaik.asn1.structures.AlgorithmID algorithm, int keyLength)
          Creates an encrypted message.
 javax.mail.Message createMessage(javax.mail.Session session, java.lang.String subject)
          Creates a MIME message container with the given subject for the given session.
 javax.mail.Message createPKCS10Message(javax.mail.Session session)
          Creates a PKCS#10 certificate request message.
 javax.mail.Message createPKCS10MultiPartMessage(javax.mail.Session session)
          Creates a PKCS#10 message where the certificate request is transferred as attachment.
 javax.mail.Message createPlainMessage(javax.mail.Session session, javax.activation.DataHandler dataHandler)
          Creates a simple plain (neither signed nor encrypted) message.
 javax.mail.Message createSignedAndEncryptedMessage(javax.mail.Session session, javax.activation.DataHandler dataHandler, boolean implicit)
          Creates a signed and encrypted message.
 javax.mail.Message createSignedMessage(javax.mail.Session session, javax.activation.DataHandler dataHandler, boolean implicit)
          Creates a signed message.
static void main(java.lang.String[] argv)
          Main method.
 void start(java.lang.String[] argv)
          Starts the demo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SMimeSendDemo

public SMimeSendDemo()
Default constructor. Reads certificates and keys from the demo keystore.

Method Detail

start

public void start(java.lang.String[] argv)
           throws java.io.IOException
Starts the demo.

Parameters:
argv - optional parameters like mailhost, sender name,...
Throws:
java.io.IOException - if an I/O related error occurs

createMessage

public javax.mail.Message createMessage(javax.mail.Session session,
                                        java.lang.String subject)
                                 throws javax.mail.MessagingException
Creates a MIME message container with the given subject for the given session.

Parameters:
session - the mail sesion
subject - the subject of the message
Returns:
the MIME message with FROM, TO, DATE and SUBJECT headers (without content)
Throws:
javax.mail.MessagingException - if the message cannot be created

createPlainMessage

public javax.mail.Message createPlainMessage(javax.mail.Session session,
                                             javax.activation.DataHandler dataHandler)
                                      throws javax.mail.MessagingException
Creates a simple plain (neither signed nor encrypted) message.

Parameters:
session - the mail session
dataHandler - the content of the message
Returns:
the plain message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createSignedAndEncryptedMessage

public javax.mail.Message createSignedAndEncryptedMessage(javax.mail.Session session,
                                                          javax.activation.DataHandler dataHandler,
                                                          boolean implicit)
                                                   throws javax.mail.MessagingException
Creates a signed and encrypted message.

Parameters:
session - the mail session
dataHandler - the content of the message to be signed and encrypted
implicit - whether to use implicit (application/pkcs7-mime) or explicit (multipart/signed) signing
Returns:
the signed and encrypted message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createSignedMessage

public javax.mail.Message createSignedMessage(javax.mail.Session session,
                                              javax.activation.DataHandler dataHandler,
                                              boolean implicit)
                                       throws javax.mail.MessagingException
Creates a signed message.

Parameters:
session - the mail session
dataHandler - the content of the message to be signed
implicit - whether to use implicit (application/pkcs7-mime) or explicit (multipart/signed) signing
Returns:
the signed message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createEncryptedMessage

public javax.mail.Message createEncryptedMessage(javax.mail.Session session,
                                                 iaik.asn1.structures.AlgorithmID algorithm,
                                                 int keyLength)
                                          throws javax.mail.MessagingException
Creates an encrypted message.

Parameters:
session - the mail session
algorithm - the content encryption algorithm to be used
keyLength - the length of the secret content encryption key to be created and used
Returns:
the encrypted message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createCertsOnlyMessage

public javax.mail.Message createCertsOnlyMessage(javax.mail.Session session)
                                          throws javax.mail.MessagingException
Creates a certs-only message.

Parameters:
session - the mail session
Returns:
the certs-only message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createCertsOnlyMultiPartMessage

public javax.mail.Message createCertsOnlyMultiPartMessage(javax.mail.Session session)
                                                   throws javax.mail.MessagingException
Creates a certs-only message where the certificate list is transferred as attachment.

Parameters:
session - the mail session
Returns:
the certs-only message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createPKCS10Message

public javax.mail.Message createPKCS10Message(javax.mail.Session session)
                                       throws javax.mail.MessagingException
Creates a PKCS#10 certificate request message.

Parameters:
session - the mail session
Returns:
the PKCS#10 certificate request message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

createPKCS10MultiPartMessage

public javax.mail.Message createPKCS10MultiPartMessage(javax.mail.Session session)
                                                throws javax.mail.MessagingException
Creates a PKCS#10 message where the certificate request is transferred as attachment.

Parameters:
session - the mail session
Returns:
the PKCS#10 certificate request message
Throws:
javax.mail.MessagingException - if an error occurs when creating the message

main

public static void main(java.lang.String[] argv)
                 throws java.io.IOException
Main method.

Throws:
java.io.IOException

IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

v6.1
(c) 2002 IAIK, (c) 2003 - 2025 SIC