public class AuthEnvelopedDataOutputStreamDemo extends java.lang.Object
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 and Description |
---|
AuthEnvelopedDataOutputStreamDemo()
Setup the demo certificate chains.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public AuthEnvelopedDataOutputStreamDemo() throws java.io.IOException
java.io.IOException
- if an file read error occurspublic byte[] createAuthEnvelopedData(byte[] message, iaik.asn1.structures.AlgorithmID contentAuthEncAlg) throws iaik.cms.CMSException, java.io.IOException
AuthEnvelopedData
and wraps it into a ContentInfo.message
- the message to be enveloped, as byte representationcontentAuthEncAlg
- the id of the content-authenticated encryption algorithmiaik.cms.CMSException
- if the AuthEnvelopedData
object cannot
be createdjava.io.IOException
- if an I/O error occurspublic byte[] getAuthEnvelopedDataStream(byte[] encoding, java.security.PrivateKey privateKey, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
encoding
- the encoded AuthEnvelopedData object, wrapped in a ContentInfoprivateKey
- 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.io.IOException
- if an I/O error occurspublic void start()
public void start(iaik.asn1.structures.AlgorithmID contentAuthEncAlg)
contentAuthEncAlg
- the id of the content-authenticated encryption algorithmpublic static void main(java.lang.String[] argv) throws java.lang.Exception
java.lang.Exception
- if an some error occurs