|
IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdemo.cms.authenticatedData.AuthenticatedDataDemo
public class AuthenticatedDataDemo
Demonstrates the usage of class AuthenticatedDataStream
and
AuthenticatedData
for recipient-specific protecting the
integrity of a message using the CMS type AuthenticatedData.
This demo requires that you have iaik_esdh.jar
(or iaik_jce_full.jar
) in your classpath.
You can download it from
https://sic.tech/products/core-crypto-toolkits/jca-jce/.
AuthenticatedDataStream
,
AuthenticatedData
Constructor Summary | |
---|---|
AuthenticatedDataDemo()
Creates and AuthenticatedDataDemo object and setups the demo certificates. |
|
AuthenticatedDataDemo(iaik.asn1.structures.AlgorithmID keyWrapAlg,
int kekLength)
Creates and AuthenticatedDataDemo object and setups the demo certificates. |
Method Summary | |
---|---|
byte[] |
createAuthenticatedData(byte[] message,
iaik.asn1.structures.AlgorithmID macAlgorithm,
int macKeyLength,
iaik.asn1.structures.AlgorithmID digestAlgorithm,
int mode)
Creates a CMS AuthenticatedData for the given message message. |
byte[] |
createAuthenticatedDataStream(byte[] message,
iaik.asn1.structures.AlgorithmID macAlgorithm,
int macKeyLength,
iaik.asn1.structures.AlgorithmID digestAlgorithm,
int mode)
Creates a CMS AuthenticatedDataStream for the given message message. |
iaik.cms.RecipientInfo[] |
createRecipients()
Creates the RecipientInfos. |
byte[] |
getAuthenticatedData(byte[] encoding,
byte[] message,
java.security.Key key,
int recipientInfoIndex)
Gets the content of the given AuthenticatedData object and
verifies the mac for the recipient identified by its index
into the recipientInfos field and uses the MAC key to verify
the authenticated data. |
byte[] |
getAuthenticatedData(byte[] encoding,
byte[] message,
java.security.Key key,
iaik.cms.KeyIdentifier recipientID)
Gets the content of the given AuthenticatedData object and
verifies the mac for the recipient identified by recipient identifier. |
byte[] |
getAuthenticatedData(byte[] encoding,
byte[] message,
java.security.Key key,
iaik.x509.X509Certificate recipientCert,
byte[] kekID)
Gets the content of the given AuthenticatedData object and
verifies the mac for the recipient identified by its recipient certificate or kekID. |
byte[] |
getAuthenticatedDataStream(byte[] encoding,
byte[] message,
java.security.Key key,
int recipientInfoIndex)
Decrypts the encrypted MAC key for the recipient identified by its index into the recipientInfos field and uses the MAC key to verify the authenticated data. |
byte[] |
getAuthenticatedDataStream(byte[] encoding,
byte[] message,
java.security.Key key,
iaik.cms.KeyIdentifier recipientID)
Decrypts the encrypted MAC key for the recipient identified by recipient identifier and uses the MAC key to verify the authenticated data. |
byte[] |
getAuthenticatedDataStream(byte[] encoding,
byte[] message,
java.security.Key key,
iaik.x509.X509Certificate recipientCert,
byte[] kekID)
Decrypts the encrypted content of the given AuthenticatedData object for
the recipient identified by its recipient certificate or kekID. |
static void |
main(java.lang.String[] argv)
Main method. |
void |
parseAuthenticatedDataWithRecipientCertOrKEKId(boolean stream,
byte[] encodedAuthenticatedData,
byte[] message)
Parses an AuthenticatedData and verifies the mac for all recipients identified by their recipient certificate (or kek). |
void |
parseAuthenticatedDataWithRecipientIdentifier(boolean stream,
byte[] encodedAuthenticatedData,
byte[] message)
Parses an AuthenticatedData and verifies the mac for all recipients identified by their recipient identifiers. |
void |
parseAuthenticatedDataWithRecipientInfoIndex(boolean stream,
byte[] encodedAuthenticatedData,
byte[] message)
Parses an AuthenticatedData and verifies the mac for all test recipients using the index into the recipientInfos field for identifying the recipient. |
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 |
---|
public AuthenticatedDataDemo() throws java.io.IOException, java.security.NoSuchAlgorithmException
SetupCMSKeyStore
.
CMS-AES256-Wrap is used as key wrap algorithm.
java.io.IOException
- if an file read error occurs
java.security.NoSuchAlgorithmException
- if no implementation for the requested key wrap algorithm is availablepublic AuthenticatedDataDemo(iaik.asn1.structures.AlgorithmID keyWrapAlg, int kekLength) throws java.io.IOException, java.security.NoSuchAlgorithmException
SetupCMSKeyStore
.
keyWrapAlg
- the key wrap algorithm to be usedkekLength
- the length of the key encryption key
java.io.IOException
- if an file read error occurs
java.security.NoSuchAlgorithmException
- if no implementation for the requested key wrap algorithm is availableMethod Detail |
---|
public byte[] createAuthenticatedDataStream(byte[] message, iaik.asn1.structures.AlgorithmID macAlgorithm, int macKeyLength, iaik.asn1.structures.AlgorithmID digestAlgorithm, int mode) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedDataStream
for the given message message.
message
- the message to be authenticated, as byte representationmacAlgorithm
- the mac algorithm to be usedmacKeyLength
- the length of the temporary MAC key to be generateddigestAlgorithm
- the digest algorithm to be used to calculate a digest
from the content if authenticated attributes should
be includedmode
- whether to include the content into the AuthenticatedData (implicit
) or to not include it
(explicit
)
AuthenticatedData
object just created
iaik.cms.CMSException
- if the AuthenticatedData
object cannot
be created
java.io.IOException
- if an I/O error occurspublic byte[] getAuthenticatedDataStream(byte[] encoding, byte[] message, java.security.Key key, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
This way of decrypting the MAC key and verifying the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo, PasswordRecipeintInfo, OtherRecipientInfo), but requires to know at what index of the recipientInfos field the RecipientInfo for the particular recipient in mind can be found. If the recipient in mind uses a RecipientInfo of type KeyAgreeRecipientInfo some processing overhead may take place because a KeyAgreeRecipientInfo may contain encrypted mac keys for more than only one recipient; since the recipientInfoIndex only specifies the RecipientInfo but not the encrypted mac key -- if there are more than only one -- repeated decryption runs may be required as long as the decryption process completes successfully.
encoding
- the AuthenticatedData
object as BER encoded byte arraymessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the mac keyrecipientInfoIndex
- the index of the right RecipientInfo
to
which the given key belongs
iaik.cms.CMSException
- if the authenticated data cannot be verified
java.io.IOException
- if a stream read/write error occurspublic byte[] getAuthenticatedDataStream(byte[] encoding, byte[] message, java.security.Key key, iaik.cms.KeyIdentifier recipientID) throws iaik.cms.CMSException, java.io.IOException
This way of decrypting the mac key may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo). The recipient in mind is identified by its recipient identifier.
encoding
- the AuthenticatedData
object as BER encoded byte arraymessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the encrypted mac keyrecipientID
- the recipient identifier uniquely identifying the key of the
recipient
iaik.cms.CMSException
- if the authenticated data cannot be verified
java.io.IOException
- if a stream read/write error occurspublic byte[] getAuthenticatedDataStream(byte[] encoding, byte[] message, java.security.Key key, iaik.x509.X509Certificate recipientCert, byte[] kekID) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedData
object for
the recipient identified by its recipient certificate or kekID.
encoding
- the AuthenticatedData
object as DER encoded byte arraymessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the messagerecipientCert
- the certificate of the recipient having a RecipientInfo of
type KeyTransRecipientInfo or KeyAgreeRecipientInfokekID
- the kekID identifying the recipient key when using a RecipientInfo
of type KEKRecipientInfo
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if a stream read/write error occurspublic byte[] createAuthenticatedData(byte[] message, iaik.asn1.structures.AlgorithmID macAlgorithm, int macKeyLength, iaik.asn1.structures.AlgorithmID digestAlgorithm, int mode) throws iaik.cms.CMSException
AuthenticatedData
for the given message message.
message
- the message to be authenticated, as byte representationmacAlgorithm
- the mac algorithm to be usedmacKeyLength
- the length of the temporary MAC key to be generateddigestAlgorithm
- the digest algorithm to be used to calculate a digest
from the content if authenticated attributes should
be includedmode
- whether to include the content into the AuthenticatedData (implicit
) or to not include it
(explicit
)
AuthenticatedData
object just created
iaik.cms.CMSException
- if the AuthenticatedData
object cannot
be createdpublic byte[] getAuthenticatedData(byte[] encoding, byte[] message, java.security.Key key, int recipientInfoIndex) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedData
object and
verifies the mac for the recipient identified by its index
into the recipientInfos field and uses the MAC key to verify
the authenticated data.
This way of decrypting the MAC key and verifying the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo), but requires to know at what index of the recipientInfos field the RecipientInfo for the particular recipient in mind can be found. If the recipient in mind uses a RecipientInfo of type KeyAgreeRecipientInfo some processing overhead may take place because a KeyAgreeRecipientInfo may contain encrypted mac keys for more than only one recipient; since the recipientInfoIndex only specifies the RecipientInfo but not the encrypted mac key -- if there are more than only one -- repeated decryption runs may be required as long as the decryption process completes successfully.
encoding
- the AuthenticatedData
object as BER encoded byte arraymessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the mac keyrecipientInfoIndex
- the index of the right RecipientInfo
to
which the given key belongs
iaik.cms.CMSException
- if the authenticated data cannot be verified
java.io.IOException
- if a IO read/write error occurspublic byte[] getAuthenticatedData(byte[] encoding, byte[] message, java.security.Key key, iaik.cms.KeyIdentifier recipientID) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedData
object and
verifies the mac for the recipient identified by recipient identifier.
This way of decrypting the content may be used for any type of RecipientInfo (KeyTransRecipientInfo, KeyAgreeRecipientInfo, KEKRecipientInfo). The recipient in mind is identified by its recipient identifier.
encoding
- the DER encoeded AuthenticatedData
object#message
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the messagerecipientID
- the recipient identifier uniquely identifying the key of the
recipient
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
- if an I/O error occurspublic byte[] getAuthenticatedData(byte[] encoding, byte[] message, java.security.Key key, iaik.x509.X509Certificate recipientCert, byte[] kekID) throws iaik.cms.CMSException, java.io.IOException
AuthenticatedData
object and
verifies the mac for the recipient identified by its recipient certificate or kekID.
encoding
- the DER encoded AuthenticatedData
ASN.1 objectmessage
- the content message, if transmitted by other means (explicit mode)key
- the key to decrypt the messagerecipientCert
- the certificate of the recipient having a RecipientInfo of
type KeyTransRecipientInfo or KeyAgreeRecipientInfokekID
- the kekID identifying the recipient key when using a RecipientInfo
of type KEKRecipientInfo
iaik.cms.CMSException
- if the message cannot be recovered
java.io.IOException
public iaik.cms.RecipientInfo[] createRecipients() throws iaik.cms.CMSException
iaik.cms.CMSException
- if an error occurs when creating the recipient infospublic void parseAuthenticatedDataWithRecipientInfoIndex(boolean stream, byte[] encodedAuthenticatedData, byte[] message) throws java.lang.Exception
stream
- whether to use AuthenticatedDataStream or AuthenticatedDataencodedAuthenticatedData
- the encoded AuthenticatedData objectmessage
- the content message, if transmitted by other means (explicit mode)
java.lang.Exception
- if some error occurs during mac key decryption / mac verificationpublic void parseAuthenticatedDataWithRecipientIdentifier(boolean stream, byte[] encodedAuthenticatedData, byte[] message) throws java.lang.Exception
stream
- whether to use AuthenticatedDataStream or AuthenticatedDataencodedAuthenticatedData
- the encoded AuthenticatedData objectmessage
- the content message, if transmitted by other means (explicit mode)
java.lang.Exception
- if some error occurs during mac key decryption / mac verificationpublic void parseAuthenticatedDataWithRecipientCertOrKEKId(boolean stream, byte[] encodedAuthenticatedData, byte[] message) throws java.lang.Exception
stream
- whether to use AuthenticatedDataStream or AuthenticatedDataencodedAuthenticatedData
- the encoded AuthenticatedData objectmessage
- the content message, if transmitted by other means (explicit mode)
java.lang.Exception
- if some error occurs during mac key decryption / mac verificationpublic 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 files
java.lang.Exception
|
IAIK CMS/SMIME Toolkit Demo API Documentation
Version 6.1 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
![]() |
v6.1 (c) 2002 IAIK, (c) 2003 - 2025 SIC |
![]() |