public class CounterSignatureDemo extends java.lang.Object
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.
CounterSignatureListener
,
CounterSignature
,
SDSEncodeListener
,
SignedDataStream
,
SignerInfo
Constructor and Description |
---|
CounterSignatureDemo()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public CounterSignatureDemo()
public byte[] createSignedDataStream(byte[] message, int mode) throws java.lang.Exception
SignedData
object.
message
- the message to be signed, as byte representationmode
- the mode indicating whether to include the content
(SignedDataStream.IMPLICIT) or not (SignedDataStream.EXPLICIT)SignedData
object just createdjava.lang.Exception
- if the SignedData
object cannot
be created for some reasonpublic byte[] getSignedDataStream(byte[] signedData, byte[] message, boolean counterSign) throws java.lang.Exception
SignedData
object and verifies the signatures
for all participated signers.signedData
- the SignedData, as BER encoded byte arraymessage
- 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 againjava.lang.Exception
- if an error occurspublic byte[] createSignedData(byte[] message, int mode) throws java.lang.Exception
SignedData
object.
message
- the message to be signed, as byte representationmode
- the mode indicating whether to include the content
(SignedDataStream.IMPLICIT) or not (SignedDataStream.EXPLICIT)SignedData
object just creatediaik.cms.CMSException
- if the SignedData
object cannot
be createdjava.lang.Exception
- if an error occurspublic byte[] getSignedData(byte[] signedData, byte[] message, boolean counterSign) throws java.lang.Exception
SignedData
object and verifies the signatures
for all participated signers.signedData
- the SignedData, as BER encoded byte arraymessage
- 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 againjava.lang.Exception
- if any error occurspublic void start()
public static void main(java.lang.String[] argv) throws java.io.IOException
java.io.IOException
- if an I/O error occurs when reading required keys
and certificates from files