|
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.envelopedData.EnvelopedDataDemo
public class EnvelopedDataDemo
Demonstrates the usage of class EnvelopedDataStream
and
EnvelopedData
for encrypting data using the CMS type
EnvelopedData.
This demo creates an EnvelopedData object and subsequently shows several ways that may be used for decrypting the content for some particular recipient.
Keys and certificates are retrieved from the demo KeyStore ("cms.keystore")
which has to be located in your current working directory and may be
created by running the SetupCMSKeyStore
program.
This demo uses TripleDES which has been deprecated by S/MIMEv4 (RFC 8551),
see AESEnvelopedDataDemo
for an AES based demo.
EnvelopedDataStream
,
EnvelopedData
,
RecipientInfo
,
KeyTransRecipientInfo
,
KeyAgreeRecipientInfo
,
KEKRecipientInfo
Constructor Summary | |
---|---|
EnvelopedDataDemo()
Creates an EnvelopedDataDemo and setups the demo certificates. |
|
EnvelopedDataDemo(iaik.asn1.structures.AlgorithmID contentEncAlg,
iaik.asn1.structures.AlgorithmID keyWrapAlg,
iaik.asn1.structures.AlgorithmID kekAlg,
int keyLength)
Creates an EnvelopedDataDemo and setups the demo certificates. |
|
EnvelopedDataDemo(iaik.asn1.structures.AlgorithmID contentEncAlg,
iaik.asn1.structures.AlgorithmID keyWrapAlg,
int keyLength)
Creates an EnvelopedDataDemo and setups the demo certificates. |
Method Summary | |
---|---|
byte[] |
createEnvelopedData(byte[] message)
Creates a CMS EnvelopedData message. |
byte[] |
createEnvelopedDataStream(byte[] message)
Creates a CMS EnvelopedDataStream message. |
iaik.cms.RecipientInfo[] |
createRecipients()
Creates the RecipientInfos. |
byte[] |
getEnvelopedData(byte[] enc,
java.security.Key key,
int recipientInfoIndex)
Decrypts the encrypted content of the given EnvelopedData object for
the recipient identified by its index into the recipientInfos field. |
byte[] |
getEnvelopedData(byte[] enc,
java.security.Key key,
iaik.cms.KeyIdentifier recipientID)
Decrypts the encrypted content of the given EnvelopedData object for
the recipient identified by recipient identifier. |
byte[] |
getEnvelopedData(byte[] enc,
java.security.Key key,
iaik.x509.X509Certificate recipientCert,
byte[] kekID)
Decrypts the encrypted content of the given EnvelopedData object for
the recipient identified by its recipient certificate or keyID. |
byte[] |
getEnvelopedDataStream(byte[] encoding,
java.security.Key key,
int recipientInfoIndex)
Decrypts the encrypted content of the given EnvelopedData object for
the recipient identified by its index into the recipientInfos field. |
byte[] |
getEnvelopedDataStream(byte[] encoding,
java.security.Key key,
iaik.cms.KeyIdentifier recipientID)
Decrypts the encrypted content of the given EnvelopedData object for
the recipient identified by recipient identifier. |
byte[] |
getEnvelopedDataStream(byte[] encoding,
java.security.Key key,
iaik.x509.X509Certificate recipientCert,
byte[] kekID)
Decrypts the encrypted content of the given EnvelopedData object for
the recipient identified by its recipient certificate or kekID. |
static void |
main(java.lang.String[] argv)
Main method. |
void |
parseEnvelopedDataWithRecipientCertOrKEKId(boolean stream,
byte[] message,
byte[] encodedEnvelopedData)
Parses an EnvelopedData and decrypts the content for all test recipients using their recipient certificate (for RecipientInfos of type KeyTransRecipientInfo or KeyAgreeRecipientInfo) or key id (for RecipientInfos of type KEKRecipientInfo) for identifying the recipient. |
void |
parseEnvelopedDataWithRecipientIdentifier(boolean stream,
byte[] message,
byte[] encodedEnvelopedData)
Parses an EnvelopedData and decrypts the content for all test recipients using their recipient identifiers for identifying the recipient. |
void |
parseEnvelopedDataWithRecipientInfoIndex(boolean stream,
byte[] message,
byte[] encodedEnvelopedData)
Parses an EnvelopedData and decrypts the content for all test recipients using the index into the recipientInfos field for identifying the recipient. |
void |
start()
Starts the test. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EnvelopedDataDemo() throws java.io.IOException, java.security.NoSuchAlgorithmException
SetupCMSKeyStore
.
java.io.IOException
- if an file read error occurs
java.security.NoSuchAlgorithmException
- if the requested TripleDES or TripleDES KeyWrap
algorithms are not supportedpublic EnvelopedDataDemo(iaik.asn1.structures.AlgorithmID contentEncAlg, iaik.asn1.structures.AlgorithmID keyWrapAlg, int keyLength) throws java.io.IOException, java.security.NoSuchAlgorithmException
SetupCMSKeyStore
.
contentEncAlg
- the content encryption algorithm to be usedkeyWrapAlg
- the key wrap algorithm to be used for wrapping the content
encryption key (for KeyAgreeRecipientInfos)keyLength
- the key length to be used (same for content encryption key
and key encryption key) (for KeyAgreeRecipientInfos and
KEKRecipientInfos)
java.io.IOException
- if an file read error occurs
java.security.NoSuchAlgorithmException
- if the requested algorithms are not supportedpublic EnvelopedDataDemo(iaik.asn1.structures.AlgorithmID contentEncAlg, iaik.asn1.structures.AlgorithmID keyWrapAlg, iaik.asn1.structures.AlgorithmID kekAlg, int keyLength) throws java.io.IOException, java.security.NoSuchAlgorithmException
SetupCMSKeyStore
.
contentEncAlg
- the content encryption algorithm to be usedkeyWrapAlg
- the key wrap algorithm to be used for wrapping the content
encryption key (for KeyAgreeRecipientInfos)kekAlg
- the name of the key encryption key algorithm to be used
(for KEKRecipientInfos)keyLength
- the key length to be used (same for content encryption key
and key encryption key) (for KeyAgreeRecipientInfos and
KEKRecipientInfos)
java.io.IOException
- if an file read error occurs
java.security.NoSuchAlgorithmException
- if the requested algorithms are not supportedMethod Detail |
---|
public byte[] createEnvelopedDataStream(byte[] message) throws iaik.cms.CMSException, java.io.IOException
EnvelopedDataStream
message.
message
- the message to be enveloped, as byte representation
EnvelopedData
object just created
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.Key key, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for
the recipient identified by its index into the recipientInfos field.
This way of decrypting the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo), but requires to know at what index of the recipientInfo 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 content-encryption keys for more than only one recipient; since the recipientInfoIndex only specifies the RecipientInfo but not the encrypted content encryption key -- if there are more than only one -- repeated decryption runs may be required as long as the decryption process completes successfully.
encoding
- the EnvelopedData
object as DER encoded byte arraykey
- the key to decrypt the messagerecipientInfoIndex
- the index into the RecipientInfo
array
to which the specified key belongs
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if a stream read/write error occurspublic byte[] getEnvelopedDataStream(byte[] encoding, java.security.Key key, iaik.cms.KeyIdentifier recipientID) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for
the recipient identified by recipient identifier.
This way of decrypting the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo). The recipient in mind is identified by its recipient identifier.
encoding
- the EnvelopedData
object as DER encoded byte arraykey
- the key to decrypt the messagerecipientID
- the recipient identifier uniquely identifying the key of the
recipient
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if a stream read/write error occurspublic byte[] getEnvelopedDataStream(byte[] encoding, java.security.Key key, iaik.x509.X509Certificate recipientCert, byte[] kekID) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for
the recipient identified by its recipient certificate or kekID.
Since recipient certificates only may be used for for RecipientInfos of type KeyTransRecipientInfo or KeyAgreeRecipientInfo, a key id has to be supplied for decrypting the content for a recipient using a KEKRecipientInfo.
encoding
- the EnvelopedData
object as DER encoded byte arraykey
- the key to decrypt the messagerecipientCert
- the certificate of the recipient having a RecipientInfo of
type KeyTransRecipientInfo or KeyAgreeRecipientInfokekID
- the kekID identifying the recipient key when using a RecipientInfo
of type KEKRecipientInfo
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if a stream read/write error occurspublic byte[] createEnvelopedData(byte[] message) throws iaik.cms.CMSException
EnvelopedData
message.
message
- the message to be enveloped, as byte representation
EnvelopedData
, as byte array
iaik.cms.CMSException
- if the EnvelopedData
object cannot
be createdpublic byte[] getEnvelopedData(byte[] enc, java.security.Key key, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for
the recipient identified by its index into the recipientInfos field.
This way of decrypting the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo), but requires to know at what index of the recipientInfo 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 content-encryption keys for more than only one recipient; since the recipientInfoIndex only specifies the RecipientInfo but not the encrypted content encryption key -- if there are more than only one -- repeated decryption runs may be required as long as the decryption process completes successfully.
enc
- the encoded EnvelopedData
key
- the key to decrypt the messagerecipientInfoIndex
- the index into the RecipientInfo
array
to which the specified key belongs
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] getEnvelopedData(byte[] enc, java.security.Key key, iaik.cms.KeyIdentifier recipientID) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for
the recipient identified by recipient identifier.
This way of decrypting the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo). The recipient in mind is identified by its recipient identifier.
enc
- the DER encoded EnvelopedData
ASN.1 objectkey
- the key to decrypt the messagerecipientID
- the recipient identifier uniquely identifying the key of the
recipient
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] getEnvelopedData(byte[] enc, java.security.Key key, iaik.x509.X509Certificate recipientCert, byte[] kekID) throws iaik.cms.CMSException, java.io.IOException
EnvelopedData
object for
the recipient identified by its recipient certificate or keyID.
Since recipient certificates only may be used for for RecipientInfos of type KeyTransRecipientInfo or KeyAgreeRecipientInfo, a key id has to be supplied for decrypting the content for a recipient using a KEKRecipientInfo.
enc
- the DER encoded EnvelopedData
ASN.1 objectkey
- the key to decrypt the messagerecipientCert
- the certificate of the recipient having a RecipientInfo of
type KeyTransRecipientInfo or KeyAgreeRecipientInfokekID
- the kekID identifying the recipient key when using a RecipientInfo
of type KEKRecipientInfo
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
public iaik.cms.RecipientInfo[] createRecipients() throws iaik.cms.CMSException
iaik.cms.CMSException
- if an error occurs when creating the recipient infospublic void parseEnvelopedDataWithRecipientInfoIndex(boolean stream, byte[] message, byte[] encodedEnvelopedData) throws java.lang.Exception
stream
- whether to use EnvelopedDataStream or EnvelopedDatamessage
- the original message (to be compared to the decryption result)encodedEnvelopedData
- the encoded EnvelopedData object
java.lang.Exception
- if some error occurs during decoding/decryptionpublic void parseEnvelopedDataWithRecipientIdentifier(boolean stream, byte[] message, byte[] encodedEnvelopedData) throws java.lang.Exception
stream
- whether to use EnvelopedDataStream or EnvelopedDatamessage
- the original message (to be compared to the decryption result)encodedEnvelopedData
- the encoded EnvelopedData object
java.lang.Exception
- if some error occurs during decoding/decryptionpublic void parseEnvelopedDataWithRecipientCertOrKEKId(boolean stream, byte[] message, byte[] encodedEnvelopedData) throws java.lang.Exception
stream
- whether to use EnvelopedDataStream or EnvelopedDatamessage
- the original message (to be compared to the decryption result)encodedEnvelopedData
- the encoded EnvelopedData object
java.lang.Exception
- if some error occurs during decoding/decryptionpublic void start()
public static void main(java.lang.String[] argv) throws java.lang.Exception
java.io.IOException
- if an I/O error occurs when reading required keys
and certificates from files
java.lang.Exception
|
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 |
![]() |