demo.pkcs
Class EnvelopedDataOAEP

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

public class EnvelopedDataOAEP
extends Object

This class uses an RSACipherProvider for en/decrypting the content encryption key of an EnvelopedData with RSA in OAEP mode.

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

Version:
File Revision 5

Constructor Summary
EnvelopedDataOAEP()
          Setup the demo certificate chains.
 
Method Summary
 byte[] createEnvelopedData(byte[] message)
          Creates a PKCS#7 EnvelopedData message.
 byte[] createEnvelopedDataStream(byte[] message)
          Creates a PKCS#7 EnvelopedDataStream message.
 byte[] getEnvelopedData(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.
 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()
          Tests the PKCS#7 content type implementations EnvelopedData, SignedData, and SignedAndEnvelopedData.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnvelopedDataOAEP

public EnvelopedDataOAEP()
                  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)
                                 throws PKCSException,
                                        IOException
Creates a PKCS#7 EnvelopedDataStream message.
Parameters:
message - the message to be enveloped, as byte representation
Returns:
the DER encoded ContentInfo containing 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 PKCSException,
                                     IOException
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message.
Parameters:
encoding - the DER encoded ContentInfo containing an EnvelopedData 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:
PKCSException - if the message cannot be recovered

createEnvelopedData

public byte[] createEnvelopedData(byte[] message)
                           throws PKCSException,
                                  IOException
Creates a PKCS#7 EnvelopedData message.
Parameters:
message - the message to be enveloped, as byte representation
Returns:
a DER encoded ContentInfo holding the EnvelopedData object just created
Throws:
PKCSException - if the EnvelopedData object cannot be created

getEnvelopedData

public byte[] getEnvelopedData(byte[] encoding,
                               PrivateKey privateKey,
                               int recipientInfoIndex)
                        throws PKCSException,
                               IOException
Decrypts the encrypted content of the given EnvelopedData object for the specified recipient and returns the decrypted (= original) message.
Parameters:
encoding - the ContentInfo encoding holding an EnvelopedData
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()
Tests the PKCS#7 content type implementations EnvelopedData, SignedData, and SignedAndEnvelopedData. An additional SignedAndEncryptedData test sequentially combines signed and enveloped data, which should be prefered to the SignedAndEnvelopedData content type.

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