public class OCBCMSParameterSpec extends OCBParameterSpec
This class extends class
to
advice the OCB implementation to not append the tag to the cipher text
(when encrypting) or provide the tag for decryption (in the case it is not
appended to the cipher text).
OCBParameterSpec
OCB is not specified for CMS, however, in alignment to GCMParameterSpec
this parameter specification class is named
OCBCMSParameterSpec
since CMS does not append the tag to the cipher text.
OCBCMSParameterSpec
(instead of an OCBParameterSpec
) the tag is not appended to
the cipher text, but saved to the OCBCMSParameterSpec
, which can be read out by
calling the Cipher method getParameters()
:
OCBCMSParameterSpec paramSpec = new OCBCMSParameterSpec(aad, nonce, tagLength); Cipher c = Cipher.getInstance("AES/OCB/NoPadding"); c.init(Cipher.ENCRYPT_MODE, key, ocbCMSParmaterSpec); byte[] encr = c.doFinal(data); AlgorithmParameters params = c.getParameters(); OCPCMSParameterSpec paramSpec = (OCBParameterSpec)params.getParameterSpec(OCBCMSParameterSpec.class); byte[] tag = paramSpec.getTag();For decryption the tag has to be be specified by the parameters (because not appended to the cipher text) in order to be able to check the authenticity of the data:
Cipher c = Cipher.getInstance("AES/OCB/NoPadding", "IAIK"); c.init(Cipher.DECRYPT_MODE, key, params); byte[] ciphertext = c.doFinal(data);
OCBParameterSpec
,
OCBParameters
Constructor and Description |
---|
OCBCMSParameterSpec()
Creates a OCB Parameter specification with default values.
|
OCBCMSParameterSpec(byte[] aaData,
byte[] nonce)
Creates a OCB Parameter specification with the given additional data and
nonce.
|
OCBCMSParameterSpec(byte[] aaData,
byte[] nonce,
byte[] tagBlock)
Creates a OCB Parameter specification with the given additional data, nonce
and TAG block.
|
OCBCMSParameterSpec(byte[] aaData,
byte[] nonce,
int tagLen)
Creates an OCB Parameter specification with the given additional data, nonce
and TAG length.
|
Modifier and Type | Method and Description |
---|---|
void |
setTag(byte[] tag)
Sets the tag value.
|
getAAD, getNonce, getTagLength, setTagLength, toString
public OCBCMSParameterSpec(byte[] aaData, byte[] nonce, int tagLen) throws java.security.InvalidAlgorithmParameterException
aaData
- the additional data that is authenticatednonce
- the nonce/ivtagLen
- number of bytes used as TAGjava.security.InvalidAlgorithmParameterException
- if the specified tag (between 1 and 16 bytes)
or nonce length (between 1 and 15 bytes) are not validpublic OCBCMSParameterSpec(byte[] aaData, byte[] nonce, byte[] tagBlock) throws java.security.InvalidAlgorithmParameterException
set
later.aaData
- the additional data that is authenticatednonce
- the nonce/ivtagBlock
- the TAG block used to verify authenticityjava.security.InvalidAlgorithmParameterException
- if the specified tag (between 1 and 16 bytes)
or nonce length (between 1 and 15 bytes) are not validpublic OCBCMSParameterSpec(byte[] aaData, byte[] nonce) throws java.security.InvalidAlgorithmParameterException
aaData
- the additional data that is authenticatednonce
- the nonce/ivjava.security.InvalidAlgorithmParameterException
- if the length of the specified nonce is not valid
(not between 1 and 15 bytes)public OCBCMSParameterSpec() throws java.security.InvalidAlgorithmParameterException
java.security.InvalidAlgorithmParameterException