IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

demo.cms.authEnvelopedData
Class AuthEnvelopedDataOutputStreamDemo

java.lang.Object
  extended by demo.cms.authEnvelopedData.AuthEnvelopedDataOutputStreamDemo

public class AuthEnvelopedDataOutputStreamDemo
extends java.lang.Object

Demonstrates the usage of class AuthEnvelopedDataOutputStream and for authenticated encrypting data using the CMS type AuthEnvelopedData according to RFC 5083.

This demo uses the AES-CCM and AES-GCM authenticated encryption algorithms as specified by RFC 5084 and the ChaCha20-Poly1305 authenticated encryption algorithm as specified by RFC 8103. The demo creates an AuthEnvelopedData object and subsequently shows several ways that may be used for decrypting the content and verifying the message authentication code for some particular recipient.
Since AES-CCM and AES-GCM are not implemented by IAIK-JCE versions prior 3.17, this demo at least may require IAIK-JCE 3.17 as cryptographic service provider. ChaCha20-Poly1305 for CMS requires IAIK-JCE version 5.62 or later.

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.


Constructor Summary
AuthEnvelopedDataOutputStreamDemo()
          Setup the demo certificate chains.
 
Method Summary
 byte[] createAuthEnvelopedData(byte[] message, iaik.asn1.structures.AlgorithmID contentAuthEncAlg)
          Creates a CMS AuthEnvelopedData and wraps it into a ContentInfo.
 byte[] getAuthEnvelopedDataStream(byte[] encoding, java.security.PrivateKey privateKey, int recipientInfoIndex)
          Decrypts the encrypted content of the given AuthEnvelopedData object and verifies the message authentication code for the specified recipient.
static void main(java.lang.String[] argv)
          Main method.
 void start()
          Starts the test.
 void start(iaik.asn1.structures.AlgorithmID contentAuthEncAlg)
          Starts the test for the given content-authenticated encryption algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthEnvelopedDataOutputStreamDemo

public AuthEnvelopedDataOutputStreamDemo()
                                  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

createAuthEnvelopedData

public byte[] createAuthEnvelopedData(byte[] message,
                                      iaik.asn1.structures.AlgorithmID contentAuthEncAlg)
                               throws iaik.cms.CMSException,
                                      java.io.IOException
Creates a CMS AuthEnvelopedData and wraps it into a ContentInfo.

Parameters:
message - the message to be enveloped, as byte representation
contentAuthEncAlg - the id of the content-authenticated encryption algorithm
Returns:
the encoded AuthEnvelopedData object just created, wrapped into a ContentInfo
Throws:
iaik.cms.CMSException - if the AuthEnvelopedData object cannot be created
java.io.IOException - if an I/O error occurs

getAuthEnvelopedDataStream

public byte[] getAuthEnvelopedDataStream(byte[] encoding,
                                         java.security.PrivateKey privateKey,
                                         int recipientInfoIndex)
                                  throws iaik.cms.CMSException,
                                         java.io.IOException
Decrypts the encrypted content of the given AuthEnvelopedData object and verifies the message authentication code for the specified recipient.

Parameters:
encoding - the encoded AuthEnvelopedData object, wrapped in a ContentInfo
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

start

public void start()
Starts the test.


start

public void start(iaik.asn1.structures.AlgorithmID contentAuthEncAlg)
Starts the test for the given content-authenticated encryption algorithm.

Parameters:
contentAuthEncAlg - the id of the content-authenticated encryption algorithm

main

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

Throws:
java.lang.Exception - if an some error occurs

IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1

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