demo.pkcs
Class TestEncryptedContentInfo

java.lang.Object
  |
  +--demo.pkcs.TestEncryptedContentInfo

public class TestEncryptedContentInfo
extends Object

This class demonstrates the EnvelopedDataStream/EncryptedContentInfoStream usages for algorithms that require a specific parameter handling.

All keys and certificates are read from a keystore created by the SetupKeyStore program.

The following algorithms are demonstrated:

This class shows how an EncryptedContentInfo is explicit created for encryptíng the content and supplying it to an EnvelopedDataStream object.

Version:
File Revision 13

Constructor Summary
TestEncryptedContentInfo()
          Setup the demo certificate chains.
 
Method Summary
 byte[] createEnvelopedDataStream(byte[] message, AlgorithmID contentEA, int keyLength)
          Creates a PKCS#7 EnvelopedDataStream message.
 byte[] getEnvelopedDataStream(byte[] encoding, 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(String[] argv)
          Starts the PKCS#7 content type implementation tests.
 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

TestEncryptedContentInfo

public TestEncryptedContentInfo()
                         throws IOException
Setup the demo certificate chains. Keys and certificate are retrieved from the demo KeyStore.
Throws:
IOException - if an file read error occurs
Method Detail

createEnvelopedDataStream

public byte[] createEnvelopedDataStream(byte[] message,
                                        AlgorithmID contentEA,
                                        int keyLength)
                                 throws Exception
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
contentEA - the content encryption algorithm
keyLength - the key length for the symmetric key
Returns:
the DER encoding of the EnvelopedData object just created
Throws:
PKCSException - if the EnvelopedData object cannot be created

getEnvelopedDataStream

public byte[] getEnvelopedDataStream(byte[] encoding,
                                     PrivateKey privateKey,
                                     int recipientInfoIndex)
                              throws Exception
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:
PKCSException - if the message cannot be recovered

start

public void start()
Starts the test.

main

public static void main(String[] argv)
                 throws Exception
Starts the PKCS#7 content type implementation tests.
Throws:
IOException - if an I/O error occurs when reading required keys and certificates from files

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK