public class CCMCMSParameterSpec
extends java.lang.Object
implements java.security.spec.AlgorithmParameterSpec
This class holds the necessary inputs (associated data, nonce, MAC length, input length and MAC block) for the encryption and decryption with the CCM mode used with CMS.
If no parameters are passed to the constructor the nonce is generated and the macLength
is set to 12.
If only macLength and/or inputLength shall be specified,
set nonce and associatedData to null
.
When having any associated data to be authenticated (but not encrypted) it has to be
be supplied to the CCM Cipher by means of a CCMCMSParameterSpec and NOT by calling
ccmCipher.updateAAD()
.
AlgorithmParameterSpec
Constructor and Description |
---|
CCMCMSParameterSpec()
Creates a CCM Parameter specification with default values.
|
CCMCMSParameterSpec(byte[] associatedData,
byte[] nonce,
byte[] macBlock)
Creates a CCM Parameter specification with the given associated data, nonce and macBlock.
|
CCMCMSParameterSpec(byte[] associatedData,
byte[] nonce,
int macLength)
Creates a CCM Parameter specification with the given associated data,
nonce and MAC length.
|
CCMCMSParameterSpec(long inputLength,
byte[] associatedData,
byte[] nonce,
byte[] macBlock)
Creates a CCM Parameter specification with the given input length,
associated data, nonce and MAC block.
|
CCMCMSParameterSpec(long inputLength,
byte[] associatedData,
byte[] nonce,
int macLength)
Creates a CCM Parameter specification with the given input length,
associated data, nonce and MAC length.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getAssociatedData()
Returns the associated data used for authentication.
|
long |
getInputLength()
Returns the length of the input data that shall be encrypted and authenticated.
|
byte[] |
getMac()
Returns the authentication block used to authenticate the plaintext and additional data.
|
int |
getMacLength()
Returns the number of bytes used from the calculated CBC-MAC-block.
|
byte[] |
getNonce()
Returns the nonce used with the IV and the CBC-MAC-calculation.
|
void |
setInputLength(long inputLength)
Set byte length of input data, needed at the beginning of the MAC-calculation.
|
void |
setMac(byte[] mac)
Sets the mac value.
|
void |
setMacLength(int macLength)
Set number of bytes that should be used as MAC.
|
public CCMCMSParameterSpec(long inputLength, byte[] associatedData, byte[] nonce, int macLength) throws java.lang.Exception
inputLength
- length of the input data that is authenticated and encryptedassociatedData
- the associated data that is authenticatednonce
- the unique noncemacLength
- number of bytes used as authentication blockjava.lang.Exception
public CCMCMSParameterSpec(long inputLength, byte[] associatedData, byte[] nonce, byte[] macBlock) throws java.lang.Exception
inputLength
- length of the input data that is authenticated and encryptedassociatedData
- the associated data that is authenticatednonce
- the unique noncemacBlock
- the MAC block used to verify authenticityjava.lang.Exception
public CCMCMSParameterSpec(byte[] associatedData, byte[] nonce, int macLength) throws java.lang.Exception
associatedData
- the associated data that is authenticatednonce
- the unique noncemacLength
- number of bytes used as authentication blockjava.lang.Exception
public CCMCMSParameterSpec(byte[] associatedData, byte[] nonce, byte[] macBlock) throws java.lang.Exception
associatedData
- the associated data that is authenticatednonce
- the unique noncemacBlock
- the MAC block used to verify authenticityjava.lang.Exception
public CCMCMSParameterSpec() throws java.lang.Exception
java.lang.Exception
public void setInputLength(long inputLength) throws java.security.InvalidAlgorithmParameterException
java.security.InvalidAlgorithmParameterException
- if the specified input length is not validpublic void setMacLength(int macLength) throws java.security.InvalidAlgorithmParameterException
java.security.InvalidAlgorithmParameterException
- if the specified MAC length is not validpublic void setMac(byte[] mac)
For CMS the mac value is not appended to the cipher data, rather it has to be set/got by/from parameters.
mac
- the mac value (not cloned)public byte[] getAssociatedData()
public int getMacLength()
public byte[] getNonce()
public byte[] getMac()
public long getInputLength()