IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

demo.cms.tsp
Class TimeStampDemo

java.lang.Object
  extended by demo.cms.tsp.TimeStampDemo

public class TimeStampDemo
extends java.lang.Object

This demo shows how to add a time stamp to a SignedData message.

For the stream-based part of this demo we use a SDSEncodeListener to add a SignatureTimeStampToken attribute the SignerInfo of a SignedDataStream object.

A SignatureTimeStampToken attribute may be included as an unsigned attribute into a SignerInfo for time stamping the signature value of a SignerInfo included in a SignedData. Using an SignedDataStream encode listener for adding a SignatureTimeStampToken may be useful when having to time stamp the signature calculated from a large data volume. Since reading all the data into memory may cause an OutOfMemory problem, class SignedDataStream should to be used for creating/encoding the SignedData object and the SignatureTimeStampToken may be added by means of a SDSEncodeListener.

The SDSEncodeListener used by this demo is implemented by class TimeStampListener assuming that only one SignerInfo is included in the SignedData. This TSA from which to get the time stamp has to be provided by its HTTP URL, i.e. this demo only works with time stamp authorities providing a HTTP service (like "http://tsp.iaik.at/tsp/TspRequest").

To run this demo, you must have the IAIK-TSP (2.x) library in your classpath. You can get it from https://sic.tech/products/public-key-infrastructure/tsp/.

See Also:
TimeStampListener, SDSEncodeListener, SignedDataStream, SignedData, SignerInfo, SignatureTimeStampToken

Constructor Summary
TimeStampDemo()
          Constructor.
 
Method Summary
 byte[] createSignedData(byte[] message, int mode)
          Creates a CMS SignedData object and adds a TimeStampToken as unsigned attribute.
 byte[] createSignedDataStream(byte[] message, int mode)
          Creates a CMS SignedData object (stream version) and adds a TimeStampToken as unsigned attribute.
 byte[] getSignedData(byte[] encoding, byte[] message)
          Parses a CMS SignedData object and verifies the signature.
 byte[] getSignedDataStream(byte[] encoding, byte[] message)
          Parses a CMS SignedData object and verifies the signature.
static void main(java.lang.String[] argv)
          Main method.
 void start()
          Starts the demo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeStampDemo

public TimeStampDemo()
Constructor. Reads required keys/certs from the demo keystore.

Method Detail

createSignedDataStream

public byte[] createSignedDataStream(byte[] message,
                                     int mode)
                              throws java.lang.Exception
Creates a CMS SignedData object (stream version) and adds a TimeStampToken as unsigned attribute.

Parameters:
message - the message to be signed, as byte representation
mode - the mode indicating whether to include the content (SignedDataStream.IMPLICIT) or not (SignedDataStream.EXPLICIT)
Returns:
the encoding of the SignedData object just created
Throws:
java.lang.Exception - if the SignedData object cannot be created for some reason

getSignedDataStream

public byte[] getSignedDataStream(byte[] encoding,
                                  byte[] message)
                           throws java.lang.Exception
Parses a CMS SignedData object and verifies the signature.

Parameters:
encoding - the SignedData, as BER encoded byte array
message - the message which was transmitted out-of-band (explicit signed), or null in implicit mode
Returns:
the content data as byte array
Throws:
java.lang.Exception - if some error occurs

createSignedData

public byte[] createSignedData(byte[] message,
                               int mode)
                        throws java.lang.Exception
Creates a CMS SignedData object and adds a TimeStampToken as unsigned attribute.

Parameters:
message - the message to be signed, as byte representation
mode - the mode indicating whether to include the content (SignedData.IMPLICIT) or not (SignedData.EXPLICIT)
Returns:
the encoding of the SignedData object just created
Throws:
java.lang.Exception - if the SignedData object cannot be created for some reason

getSignedData

public byte[] getSignedData(byte[] encoding,
                            byte[] message)
                     throws java.lang.Exception
Parses a CMS SignedData object and verifies the signature.

Parameters:
encoding - the SignedData, as BER encoded byte array
message - the message which was transmitted out-of-band (explicit signed), or null in implicit mode
Returns:
the content data as byte array
Throws:
java.lang.Exception - if some error occurs

start

public void start()
Starts the demo.


main

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

Throws:
java.io.IOException - if an I/O error occurs when reading required keys and certificates from files

IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

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