IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

demo.cms.signedData
Class CounterSignatureDemo

java.lang.Object
  extended by demo.cms.signedData.CounterSignatureDemo

public class CounterSignatureDemo
extends java.lang.Object

This class demonstrates the usage of the CounterSignature attribute.

A CounterSignature attribute may be included as an unsigned attribute into a SignerInfo for counter signing (signing in serial) the signature value of a SignerInfo included in a SignedData. The value of a CounterSignature attribute itself is a SignerInfo.

This demo shows how a CounterSignature attribute may be added to some SignerInfo that belongs to a SignedData object just parsed/verified. This class demonstrates adding/verifying of a CounterSignature attribute to both the stream and the non-stream implementations of the SignedData type. Since when parsing an implicit -- where the content is included -- SignedData object, SignerInfos can not accessed before the data has been processed, adding a counter signature to a SignedDataStream may require a different proceeding than adding it to a SignedData object. For that reason a CounterSignatureListener is used for the stream demos to listen on and add the counter signature during the encoding process.

See Also:
CounterSignatureListener, CounterSignature, SDSEncodeListener, SignedDataStream, SignerInfo

Constructor Summary
CounterSignatureDemo()
          Constructor.
 
Method Summary
 byte[] createSignedData(byte[] message, int mode)
          Creates a CMS SignedData object.
 byte[] createSignedDataStream(byte[] message, int mode)
          Creates a CMS SignedData object.
 byte[] getSignedData(byte[] signedData, byte[] message, boolean counterSign)
          Parses a CMS SignedData object and verifies the signatures for all participated signers.
 byte[] getSignedDataStream(byte[] signedData, byte[] message, boolean counterSign)
          Parses a CMS SignedData object and verifies the signatures for all participated signers.
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

CounterSignatureDemo

public CounterSignatureDemo()
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.

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[] signedData,
                                  byte[] message,
                                  boolean counterSign)
                           throws java.lang.Exception
Parses a CMS SignedData object and verifies the signatures for all participated signers.

Parameters:
signedData - the SignedData, as BER encoded byte array
message - the the message which was transmitted out-of-band (explicit signed)
counterSign - whether to use a SDSEncodeListener to add a SignerInfo and encode the SignedData again
Returns:
the inherent message as byte array, or the BER encoded SignedData if it shall be encoded again (counter signing phase)
Throws:
java.lang.Exception - if an error occurs

createSignedData

public byte[] createSignedData(byte[] message,
                               int mode)
                        throws java.lang.Exception
Creates a CMS SignedData object.

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:
iaik.cms.CMSException - if the SignedData object cannot be created
java.lang.Exception - if an error occurs

getSignedData

public byte[] getSignedData(byte[] signedData,
                            byte[] message,
                            boolean counterSign)
                     throws java.lang.Exception
Parses a CMS SignedData object and verifies the signatures for all participated signers.

Parameters:
signedData - the SignedData, as BER encoded byte array
message - the the message which was transmitted out-of-band (explicit signed)
counterSign - whether to use a SDSEncodeListener to add a SignerInfo and encode the SignedData again
Returns:
the inherent message as byte array, or the BER encoded SignedData if it shall be encoded again (counter signing phase)
Throws:
java.lang.Exception - if any 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