public class CAST128EnvelopedDataDemo extends java.lang.Object
This demo compares the usage of class EnvelopedDataStream for encrypting the content using CAST128 with automatical (transparent) key/parameter handling against explicit key/parameter/EncrypedContentInfoStream handling.
All keys and certificates are read from a keystore created by the SetupCMSKeyStore program.
CAST parameters are defined as:
Parameters ::= SEQUENCE {
iv OCTET STRING DEFAULT 0,
keyLength INTEGER }
| Constructor and Description |
|---|
CAST128EnvelopedDataDemo()
Setup the demo certificate chains.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
createEncryptedContentInfoStream(byte[] message,
iaik.asn1.structures.AlgorithmID cea,
int keyLength)
Creates a CMS
EnvelopedDataStream message. |
byte[] |
createEnvelopedDataStream(byte[] message,
iaik.asn1.structures.AlgorithmID contentEA,
int keyLength)
Creates a CMS
EnvelopedDataStream message. |
byte[] |
getEncryptedContentInfoStream(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[] |
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. |
static void |
main(java.lang.String[] argv)
The main method.
|
void |
start()
Starts the test.
|
public CAST128EnvelopedDataDemo() throws java.io.IOException
java.io.IOException - if an file read error occurspublic byte[] createEnvelopedDataStream(byte[] message, iaik.asn1.structures.AlgorithmID contentEA, int keyLength) throws java.lang.Exception
EnvelopedDataStream message.
message - the message to be enveloped, as byte representationcontentEA - the content encryption algorithmkeyLength - the key length for the symmetric keyEnvelopedData object just createdjava.lang.Exception - if the EnvelopedData object cannot
be createdpublic byte[] createEncryptedContentInfoStream(byte[] message, iaik.asn1.structures.AlgorithmID cea, int keyLength) throws java.lang.Exception
EnvelopedDataStream message.
Keys and parameters, and EncryptedContentInfoStream are created outside the EnvelopedDataStream class.
message - the message to be enveloped, as byte representationcea - the content encryption algorithmkeyLength - the key length for the symmetric keyEnvelopedData object just createdjava.lang.Exception - if the EnvelopedData object cannot
be createdpublic byte[] getEncryptedContentInfoStream(byte[] encoding, java.security.PrivateKey privateKey, int recipientInfoIndex) throws java.lang.Exception
EnvelopedData object for the
specified recipient and returns the decrypted (= original) message.
Decryption and cipher setup and EncryptedContentInfoStrean processing is performed outside class EnvelopedDataStream.
encoding - the EnvelopedData object as DER encoded byte arrayprivateKey - the private key to decrypt the messagerecipientInfoIndex - the index into the RecipientInfo array
to which the specified private key belongsiaik.cms.CMSException - if the message cannot be recoveredjava.lang.Exceptionpublic byte[] getEnvelopedDataStream(byte[] encoding, java.security.PrivateKey privateKey, int recipientInfoIndex) throws java.lang.Exception
EnvelopedData object for the
specified recipient and returns the decrypted (= original) message.encoding - the EnvelopedData object as DER encoded byte arrayprivateKey - the private key to decrypt the messagerecipientInfoIndex - the index into the RecipientInfo array
to which the specified private key belongsjava.lang.Exception - if the message cannot be recoveredpublic void start()
public static void main(java.lang.String[] argv) throws java.lang.Exception
java.lang.Exception - if some error occurs