public class PKCS7CMSEncryptedContentInfoDemo extends java.lang.Object
This class shows the compatibility to PKCS#7.
All keys and certificates are read from a keystore created by the SetupCMSKeyStore program.
The following algorithms are demonstrated:
RC2-CBC parameter ::= SEQUENCE {
rc2ParameterVersion INTEGER,
iv OCTET STRING (8)}
For the effective-key-bits of 40, 64, and 128, the
rc2ParameterVersion values are 160, 120, 58 respectively.
Parameters ::= SEQUENCE {
iv OCTET STRING DEFAULT 0,
keyLength INTEGER }
RC2EnvelopedDataDemo for an example.
Note that the usage of algorithms like RC2 is deprecated but used here for this demo since it requires a specific parameter handling.
| Constructor and Description |
|---|
PKCS7CMSEncryptedContentInfoDemo()
Setup the demo certificate chains.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
createEnvelopedDataStream(byte[] message,
iaik.asn1.structures.AlgorithmID contentEA,
int keyLength)
Creates a CMS
EnvelopedDataStream message. |
byte[] |
createPKCS7EnvelopedDataStream(byte[] message,
iaik.asn1.structures.AlgorithmID cea,
int keyLength)
Creates a PKCS#7
EnvelopedDataStream message. |
byte[] |
getEnvelopedDataStream(byte[] encoding,
java.security.PrivateKey privateKey,
int recipientInfoIndex)
Decrypts the encrypted content of the given CMS
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 PKCS#7
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 PKCS7CMSEncryptedContentInfoDemo() 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[] 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 byte[] createPKCS7EnvelopedDataStream(byte[] message, iaik.asn1.structures.AlgorithmID cea, int keyLength) throws java.lang.Exception
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.
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[] getPKCS7EnvelopedDataStream(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.io.IOException - if an I/O error occurs when reading required keys
and certificates from filesjava.lang.Exception