|
IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdemo.cms.basic.CMSDemo
public class CMSDemo
This class shows some CMS examples where the content types are wrapped into a ContentInfo.
All keys and certificates are read from a keystore created by the SetupCMSKeyStore program.
This class demonstrates how to wrap the several CMS types into ContentInfos:
Additionally, a SignedAndEncryptedData test is performed, which is a sequential combination of signed and enveloped data content types.
All sub-tests use the same proceeding: A test message is properly processed to give the requested content type object, which subsequently is encoded to be "sent" to some recipient, who parses it for the inherent structures.
Constructor Summary | |
---|---|
CMSDemo()
Setup the demo certificate chains. |
Method Summary | |
---|---|
byte[] |
createAuthenticatedData(byte[] message,
boolean includeAuthAttrs,
int mode)
Creates a CMS AuthenticatedData for the given message message. |
byte[] |
createAuthenticatedDataStream(byte[] message,
boolean includeAuthAttrs,
int mode)
Creates a CMS AuthenticatedDataStream for the given message message. |
byte[] |
createData(byte[] message)
Creates a CMS Data object. |
byte[] |
createDataStream(byte[] message)
Creates a CMS Data object and wraps it into a ContentInfo. |
byte[] |
createDigestedData(byte[] message,
int mode)
Creates a CMS DigestedData object. |
byte[] |
createDigestedDataStream(byte[] message,
int mode)
Creates a CMS DigestedData object. |
byte[] |
createEncryptedData(byte[] message,
iaik.asn1.structures.AlgorithmID pbeAlgorithm,
char[] password)
Creates a CMS EncryptedData message. |
byte[] |
createEncryptedDataStream(byte[] message,
iaik.asn1.structures.AlgorithmID pbeAlgorithm,
char[] password)
Creates a CMS EncryptedDataStream message. |
byte[] |
createEnvelopedData(byte[] message)
Creates a CMS EnvelopedData message and wraps it into a ContentInfo. |
byte[] |
createEnvelopedDataStream(byte[] message)
Creates a CMS EnvelopedData and wraps it into a ContentInfo. |
byte[] |
createSignedAndEncryptedData(byte[] message)
Creates a SignedAndEncrypted (i.e. sequential combination of
SignedData and EnvelopedData ) object. |
byte[] |
createSignedAndEncryptedDataStream(byte[] message)
Creates a SignedAndEncrypted (i.e. sequential combination of
SignedData and EnvelopedData ). |
byte[] |
createSignedData(byte[] message,
int mode)
Creates a CMS SignedData object and wraps it into a ContentInfo. |
byte[] |
createSignedDataStream(byte[] message,
int mode)
Creates a CMS SignedData object ans wraps it into a ContentInfo. |
byte[] |
getAuthenticatedData(byte[] encoding,
byte[] message,
java.security.PrivateKey key,
int recipientInfoIndex)
Decrypts the encrypted MAC key for the recipient identified by its index into the recipientInfos field and uses the MAC key to verify the authenticated data. |
byte[] |
getAuthenticatedDataStream(byte[] encoding,
byte[] message,
java.security.PrivateKey key,
int recipientInfoIndex)
Decrypts the encrypted MAC key for the recipient identified by its index into the recipientInfos field and uses the MAC key to verify the authenticated data. |
byte[] |
getData(byte[] encoding)
Parses a CMS Data object. |
byte[] |
getDataStream(byte[] data)
Parses a CMS Data object. |
byte[] |
getDigestedData(byte[] encoding,
byte[] message)
Parses a CMS DigestedData object and verifies the hash value. |
byte[] |
getDigestedDataStream(byte[] digestedData,
byte[] message)
Parses a CMS DigestedData object and verifies the hash. |
byte[] |
getEncryptedData(byte[] encoding,
char[] password)
Decrypts the PBE-encrypted content of the given EncryptedData object
using the specified password and returns the decrypted (= original) message. |
byte[] |
getEncryptedDataStream(byte[] encoding,
char[] password)
Decrypts the PBE-encrypted content of the given EncryptedData object
using the specified password and returns the decrypted (= original) message. |
byte[] |
getEnvelopedData(byte[] encoding,
java.security.PrivateKey privateKey,
int recipientInfoIndex)
Decrypts the encrypted content of the given EnvelopedData object for the
specified recipient and returns the decrypted (= original) message. |
byte[] |
getEnvelopedDataStream(byte[] encoding,
java.security.PrivateKey privateKey,
int recipientInfoIndex)
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message. |
byte[] |
getSignedAndEncryptedData(byte[] encoding)
Recovers the original message and verifies the signature. |
byte[] |
getSignedAndEncryptedDataStream(byte[] in)
Recovers the original message and verifies the signature. |
byte[] |
getSignedData(byte[] encoding,
byte[] message)
Parses a CMS SignedData object and verifies the signatures
for all participated signers. |
byte[] |
getSignedDataStream(byte[] signedData,
byte[] message)
Parses a CMS SignedData object and verifies the signatures
for all participated signers. |
static void |
main(java.lang.String[] argv)
Starts the CMS content type implementation tests. |
void |
start()
Tests the CMS content type implementations Data , EnvelopedData ,
SignedData , DigestedData , EncryptedData . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CMSDemo() throws java.io.IOException
java.io.IOException
- if an file read error occursMethod Detail |
---|
public byte[] createDataStream(byte[] message) throws iaik.cms.CMSException, java.io.IOException
Data
object and wraps it into a ContentInfo.
message
- the message to be sent, as byte representation
Data
object just created
iaik.cms.CMSException
- if the Data
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getDataStream(byte[] data) throws iaik.cms.CMSException, java.io.IOException
Data
object.
data
- the encoded ContentInfo holding the Data
iaik.cms.CMSException
- if an parsing exception occurs
java.io.IOException
- if an I/O error occurspublic byte[] createEnvelopedDataStream(byte[] message) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
and wraps it into a ContentInfo.
message
- the message to be enveloped, as byte representation
iaik.cms.CMSException
- if the EnvelopedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getEnvelopedDataStream(byte[] encoding, java.security.PrivateKey privateKey, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
encoding
- the encoded ContentInfo containing an EnvelopedData objectprivateKey
- the private key to decrypt the messagerecipientInfoIndex
- the index into the RecipientInfo
array
to which the specified private key belongs
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] createSignedDataStream(byte[] message, int mode) throws iaik.cms.CMSException, java.io.IOException
SignedData
object ans wraps it into a ContentInfo.
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 created
iaik.cms.CMSException
- if the SignedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getSignedDataStream(byte[] signedData, byte[] message) throws iaik.cms.CMSException, java.io.IOException
SignedData
object and verifies the signatures
for all participated signers.
signedData
- the ContentInfo with inherent SignedData, as BER encoded byte arraymessage
- the the message which was transmitted out-of-band (explicit signed)
null
if there
is no message included into the supplied SignedData
object
iaik.cms.CMSException
- if any signature does not verify
java.io.IOException
- if an I/O error occurspublic byte[] createSignedAndEncryptedDataStream(byte[] message) throws iaik.cms.CMSException, java.io.IOException
SignedData
and EnvelopedData
).
message
- the message to be signed and encrypted, as byte representation
iaik.cms.CMSException
- if the the SignedData
or
EnvelopedData
object cannot be created
java.io.IOException
- if an I/O error occurspublic byte[] getSignedAndEncryptedDataStream(byte[] in) throws iaik.cms.CMSException, java.io.IOException
in
- the encoded CMS object
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] createDigestedDataStream(byte[] message, int mode) throws iaik.cms.CMSException, java.io.IOException
DigestedData
object.
message
- the message to be digested, as byte representation
iaik.cms.CMSException
- if the DigestedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getDigestedDataStream(byte[] digestedData, byte[] message) throws iaik.cms.CMSException, java.io.IOException
DigestedData
object and verifies the hash.
digestedData
- the encoded ContentInfo holding a DigestedData objectmessage
- the the message which was transmitted out-of-band
null
if there
is no message included into the supplied DigestedData
object
iaik.cms.CMSException
- if any signature does not verify
java.io.IOException
- if an I/O error occurspublic byte[] createEncryptedDataStream(byte[] message, iaik.asn1.structures.AlgorithmID pbeAlgorithm, char[] password) throws iaik.cms.CMSException, java.io.IOException
EncryptedDataStream
message.
The supplied content is PBE-encrypted using the specified password.
message
- the message to be encrypted, as byte representationpbeAlgorithm
- the PBE algorithm to be usedpassword
- the password
EncryptedData
object just created
iaik.cms.CMSException
- if the EncryptedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getEncryptedDataStream(byte[] encoding, char[] password) throws iaik.cms.CMSException, java.io.IOException
EncryptedData
object
using the specified password and returns the decrypted (= original) message.
encoding
- the encoded ContentInfo holding an EncryptedData
objectpassword
- the password to decrypt the message
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] createAuthenticatedDataStream(byte[] message, boolean includeAuthAttrs, int mode) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedDataStream
for the given message message.
Attention: This AuthenticatedData demo uses RSA as key management technique.
In practice (see RFC 5652) a key management technique that provides data origin
authentication should be used like, for instance, Static-Static Diffie-Hellman when
both the originator and recipient public keys are bound to appropriate identities
in X.509 certificates, see, for instance, AuthenticatedDataDemo
.
message
- the message to be authenticated, as byte representationincludeAuthAttrs
- whether to include authenticated attributesmode
- the mode indicating whether to include the content
(AuthenticatedDataStream.IMPLICIT) or not (AuthenticatedDataStream.EXPLICIT)
AuthenticatedData
object, wrapped in a ContentInfo
iaik.cms.CMSException
- if the AuthenticatedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getAuthenticatedDataStream(byte[] encoding, byte[] message, java.security.PrivateKey key, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
This way of decrypting the MAC key and verifying the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo), but requires to know at what index of the recipientInfos field the RecipientInfo for the particular recipient in mind can be found. If the recipient in mind uses a RecipientInfo of type KeyAgreeRecipientInfo some processing overhead may take place because a KeyAgreeRecipientInfo may contain encrypted mac keys for more than only one recipient; since the recipientInfoIndex only specifies the RecipientInfo but not the encrypted mac key -- if there are more than only one -- repeated decryption runs may be required as long as the decryption process completes successfully.
Attention: This AuthenticatedData demo uses RSA as key management technique.
In practice (see RFC 5652) a key management technique that provides data origin
authentication should be used like, for instance, Static-Static Diffie-Hellman when
both the originator and recipient public keys are bound to appropriate identities
in X.509 certificates, see, for instance, AuthenticatedDataDemo
.
encoding
- the BER encoded ContentInfo holding the AuthenticatedData
objectmessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the mac keyrecipientInfoIndex
- the index of the right RecipientInfo
to
which the given key belongs
iaik.cms.CMSException
- if the authenticated data cannot be verified
java.io.IOException
- if a stream read/write error occurspublic byte[] createData(byte[] message) throws iaik.cms.CMSException
Data
object.
message
- the message to be sent, as byte representation
Data
object just created
iaik.cms.CMSException
- if the Data
object cannot
be createdpublic byte[] getData(byte[] encoding) throws iaik.cms.CMSException, java.io.IOException
Data
object.
encoding
- the DER encoded ContentInfo holding with inherent Data
iaik.cms.CMSException
- if an parsing exception occurs
java.io.IOException
- if an I/O related error occurspublic byte[] createEnvelopedData(byte[] message) throws iaik.cms.CMSException
EnvelopedData
message and wraps it into a ContentInfo.
message
- the message to be enveloped, as byte representation
iaik.cms.CMSException
- if the EnvelopedData
object cannot
be createdpublic byte[] getEnvelopedData(byte[] encoding, java.security.PrivateKey privateKey, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for the
specified recipient and returns the decrypted (= original) message.
encoding
- the DER encoded ContentInfo holding an EnvelopedDataprivateKey
- the private key to decrypt the messagerecipientInfoIndex
- the index into the RecipientInfo
array
to which the specified private key belongs
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
public byte[] createSignedData(byte[] message, int mode) throws iaik.cms.CMSException
SignedData
object and wraps it into a ContentInfo.
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 created
iaik.cms.CMSException
- if the SignedData
object cannot
be createdpublic byte[] getSignedData(byte[] encoding, byte[] message) throws iaik.cms.CMSException, java.io.IOException
SignedData
object and verifies the signatures
for all participated signers.
encoding
- the ContentInfo with inherent SignedData
object, as DER encodingmessage
- the the message which was transmitted out-of-band (explicit signed)
null
if there
is no message included into the supplied SignedData
object
iaik.cms.CMSException
- if any signature does not verify
java.io.IOException
- if an I/O error occurspublic byte[] createSignedAndEncryptedData(byte[] message) throws iaik.cms.CMSException
SignedData
and EnvelopedData
) object.
message
- the message to be signed and encrypted, as byte representation
iaik.cms.CMSException
- if the the SignedData
or
EnvelopedData
object cannot be createdpublic byte[] getSignedAndEncryptedData(byte[] encoding) throws iaik.cms.CMSException, java.io.IOException
encoding
- the DER encoded ContentInfo holding a SignedAndEnryptedData object
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] createDigestedData(byte[] message, int mode) throws iaik.cms.CMSException
DigestedData
object.
message
- the message to be digested, as byte representation
DigestedData
wrapped into a ContentInfo, as DER encoding
iaik.cms.CMSException
- if the DigestedData
object cannot
be createdpublic byte[] getDigestedData(byte[] encoding, byte[] message) throws iaik.cms.CMSException, java.io.IOException
DigestedData
object and verifies the hash value.
encoding
- the ContentInfo holding a DigestedData
, as DER encodingmessage
- the the message which was transmitted out-of-band (explicit digested)
iaik.cms.CMSException
- if some parsing exception occurs
java.io.IOException
- if an I/O error occurspublic byte[] createEncryptedData(byte[] message, iaik.asn1.structures.AlgorithmID pbeAlgorithm, char[] password) throws iaik.cms.CMSException
EncryptedData
message.
The supplied content is PBE-encrypted using the specified password.
message
- the message to be encrypted, as byte representationpbeAlgorithm
- the PBE algorithm to be usedpassword
- the password
EncryptedData
object wrapped into a ContentInfo, as DER encoding
iaik.cms.CMSException
- if the EncryptedData
object cannot
be createdpublic byte[] getEncryptedData(byte[] encoding, char[] password) throws iaik.cms.CMSException, java.io.IOException
EncryptedData
object
using the specified password and returns the decrypted (= original) message.
encoding
- the DER encoded ContentInfo holding the EncryptedData
objectpassword
- the password to decrypt the message
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] createAuthenticatedData(byte[] message, boolean includeAuthAttrs, int mode) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedData
for the given message message.
Attention: This AuthenticatedData demo uses RSA as key management technique.
In practice (see RFC 5652) a key management technique that provides data origin
authentication should be used like, for instance, Static-Static Diffie-Hellman when
both the originator and recipient public keys are bound to appropriate identities
in X.509 certificates, see, for instance, AuthenticatedDataDemo
.
message
- the message to be authenticated, as byte representationincludeAuthAttrs
- whether to include authenticated attributesmode
- the mode indicating whether to include the content
(AuthenticatedData.IMPLICIT) or not (AuthenticatedDatam.EXPLICIT)
AuthenticatedData
object, wrapped in a ContentInfo
iaik.cms.CMSException
- if the AuthenticatedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getAuthenticatedData(byte[] encoding, byte[] message, java.security.PrivateKey key, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
This way of decrypting the MAC key and verifying the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo), but requires to know at what index of the recipientInfos field the RecipientInfo for the particular recipient in mind can be found. If the recipient in mind uses a RecipientInfo of type KeyAgreeRecipientInfo some processing overhead may take place because a KeyAgreeRecipientInfo may contain encrypted mac keys for more than only one recipient; since the recipientInfoIndex only specifies the RecipientInfo but not the encrypted mac key -- if there are more than only one -- repeated decryption runs may be required as long as the decryption process completes successfully.
Attention: This AuthenticatedData demo uses RSA as key management technique.
In practice (see RFC 5652) a key management technique that provides data origin
authentication should be used like, for instance, Static-Static Diffie-Hellman when
both the originator and recipient public keys are bound to appropriate identities
in X.509 certificates, see, for instance, AuthenticatedDataDemo
.
encoding
- the DER encoded ContentInfo holding the AuthenticatedData
objectmessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the mac keyrecipientInfoIndex
- the index of the right RecipientInfo
to
which the given key belongs
iaik.cms.CMSException
- if the authenticated data cannot be verified
java.io.IOException
- if a IO read/write error occurspublic void start()
Data
, EnvelopedData
,
SignedData
, DigestedData
, EncryptedData
.
An additional SignedAndEncryptedData test sequentially combines
signed and enveloped data.
public static void main(java.lang.String[] argv) throws java.lang.Exception
java.lang.Exception
- if some error occurs
|
IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
![]() |
v6.1 (c) 2002 IAIK, (c) 2003 - 2025 SIC |
![]() |