IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

demo.cms.pkcs7cms
Class PKCS7CMSEnvelopedDataDemo

java.lang.Object
  extended by demo.cms.pkcs7cms.PKCS7CMSEnvelopedDataDemo

public class PKCS7CMSEnvelopedDataDemo
extends java.lang.Object

Compares the usage of the IAIK CMS EnvelopedData(Stream) implementation against the IAIK PKCS#7 EnvelopedData(Stream) implementation.


Constructor Summary
PKCS7CMSEnvelopedDataDemo()
          Setup the demo certificate chains.
 
Method Summary
 iaik.asn1.ASN1Object createEnvelopedData(byte[] message)
          Creates a CMS EnvelopedData message.
 byte[] createEnvelopedDataStream(byte[] message)
          Creates a CMS EnvelopedDataStream message.
 iaik.asn1.ASN1Object createPKCS7EnvelopedData(byte[] message)
          Creates a PKCS#7 EnvelopedData message.
 byte[] createPKCS7EnvelopedDataStream(byte[] message)
          Creates a PKCS#7 EnvelopedDataStream message.
 byte[] getEnvelopedData(iaik.asn1.ASN1Object obj, 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[] getPKCS7EnvelopedData(iaik.asn1.ASN1Object obj, 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[] getPKCS7EnvelopedDataStream(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.
static void main(java.lang.String[] argv)
          The main method.
 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

PKCS7CMSEnvelopedDataDemo

public PKCS7CMSEnvelopedDataDemo()
                          throws java.io.IOException
Setup the demo certificate chains. Keys and certificate are retrieved from the demo KeyStore.

Throws:
java.io.IOException - if an file read error occurs
Method Detail

createEnvelopedDataStream

public byte[] createEnvelopedDataStream(byte[] message)
                                 throws iaik.cms.CMSException,
                                        java.io.IOException
Creates a CMS EnvelopedDataStream message.

The enveloped-data content type consists of encrypted content of any type and encrypted content-encryption keys for one or more recipients. The combination of encrypted content and encrypted content-encryption key for a recipient is a "digital envelope" for that recipient. Any type of content can be enveloped for any number of recipients in parallel.

Parameters:
message - the message to be enveloped, as byte representation
Returns:
the DER encoding of the EnvelopedData object just created
Throws:
iaik.cms.CMSException - if the EnvelopedData object cannot be created
java.io.IOException - if an I/O error occurs

getEnvelopedDataStream

public byte[] getEnvelopedDataStream(byte[] encoding,
                                     java.security.PrivateKey privateKey,
                                     int recipientInfoIndex)
                              throws iaik.cms.CMSException,
                                     java.io.IOException
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message.

Parameters:
encoding - the EnvelopedData object as DER encoded byte array
privateKey - the private key to decrypt the message
recipientInfoIndex - the index into the RecipientInfo array to which the specified private key belongs
Returns:
the recovered message, as byte array
Throws:
iaik.cms.CMSException - if the message cannot be recovered
java.io.IOException - if an I/O error occurs

createEnvelopedData

public iaik.asn1.ASN1Object createEnvelopedData(byte[] message)
                                         throws iaik.cms.CMSException
Creates a CMS EnvelopedData message.

The enveloped-data content type consists of encrypted content of any type and encrypted content-encryption keys for one or more recipients. The combination of encrypted content and encrypted content-encryption key for a recipient is a "digital envelope" for that recipient. Any type of content can be enveloped for any number of recipients in parallel.

Parameters:
message - the message to be enveloped, as byte representation
Returns:
the EnvelopedData as ASN.1 object
Throws:
iaik.cms.CMSException - if the EnvelopedData object cannot be created

getEnvelopedData

public byte[] getEnvelopedData(iaik.asn1.ASN1Object obj,
                               java.security.PrivateKey privateKey,
                               int recipientInfoIndex)
                        throws iaik.cms.CMSException
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message.

Parameters:
obj - the EnvelopedData as ASN.1 object
privateKey - the private key to decrypt the message
recipientInfoIndex - the index into the RecipientInfo array to which the specified private key belongs
Returns:
the recovered message, as byte array
Throws:
iaik.cms.CMSException - if the message cannot be recovered

createPKCS7EnvelopedDataStream

public byte[] createPKCS7EnvelopedDataStream(byte[] message)
                                      throws iaik.pkcs.PKCSException,
                                             java.io.IOException
Creates a PKCS#7 EnvelopedDataStream message.

The enveloped-data content type consists of encrypted content of any type and encrypted content-encryption keys for one or more recipients. The combination of encrypted content and encrypted content-encryption key for a recipient is a "digital envelope" for that recipient. Any type of content can be enveloped for any number of recipients in parallel.

Parameters:
message - the message to be enveloped, as byte representation
Returns:
the DER encoding of the EnvelopedData object just created
Throws:
iaik.pkcs.PKCSException - if the EnvelopedData object cannot be created
java.io.IOException - if an I/O error occurs

getPKCS7EnvelopedDataStream

public byte[] getPKCS7EnvelopedDataStream(byte[] encoding,
                                          java.security.PrivateKey privateKey,
                                          int recipientInfoIndex)
                                   throws iaik.pkcs.PKCSException,
                                          java.io.IOException
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message.

Parameters:
encoding - the EnvelopedData object as DER encoded byte array
privateKey - the private key to decrypt the message
recipientInfoIndex - the index into the RecipientInfo array to which the specified private key belongs
Returns:
the recovered message, as byte array
Throws:
iaik.pkcs.PKCSException - if the message cannot be recovered
java.io.IOException - if an I/O error occurs

createPKCS7EnvelopedData

public iaik.asn1.ASN1Object createPKCS7EnvelopedData(byte[] message)
                                              throws iaik.pkcs.PKCSException,
                                                     java.io.IOException
Creates a PKCS#7 EnvelopedData message.

The enveloped-data content type consists of encrypted content of any type and encrypted content-encryption keys for one or more recipients. The combination of encrypted content and encrypted content-encryption key for a recipient is a "digital envelope" for that recipient. Any type of content can be enveloped for any number of recipients in parallel.

Parameters:
message - the message to be enveloped, as byte representation
Returns:
the EnvelopedData as ASN.1 object
Throws:
iaik.pkcs.PKCSException - if the EnvelopedData object cannot be created
java.io.IOException - if an I/O error occurs

getPKCS7EnvelopedData

public byte[] getPKCS7EnvelopedData(iaik.asn1.ASN1Object obj,
                                    java.security.PrivateKey privateKey,
                                    int recipientInfoIndex)
                             throws iaik.pkcs.PKCSException,
                                    java.io.IOException
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message.

Parameters:
obj - the EnvelopedData as ASN.1 object
privateKey - the private key to decrypt the message
recipientInfoIndex - the index into the RecipientInfo array to which the specified private key belongs
Returns:
the recovered message, as byte array
Throws:
iaik.pkcs.PKCSException - if the message cannot be recovered
java.io.IOException - if an I/O error occurs

start

public void start()
Starts the test.


main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
The main method.

Throws:
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

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