public class GCMParameters
extends java.security.AlgorithmParametersSpi
GCMParameters ::= SEQUENCE { aes-nonce OCTET STRING, -- recommended size is 12 octets aes-ICVlen AES-GCM-ICVlen DEFAULT 12 } AES-GCM-ICVlen ::= INTEGER (12 | 13 | 14 | 15 | 16)As stated in the NIST Special Publication 800-38D also the MAC length of 4 and 8 bytes are possible. Additionally, this class holds the GCM parameter associated data and MAC block.
GCMParameters can be generated by calling one of the AlgorithmParameters.getInstance
methods. Subsequently, the new AlgorithmParameters object must be initialized with
a proper parameter specification (class GCMParameterSpec is recommended) or a DER encoded byte array, e.g.
GCMParameterSpec gcmParamSpec = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("GCM", "IAIK"); params.init(gcmParamsSpec);The GCMParameters can also be initialized with an IvParameterSpec object. In this case, the specified IV will be used as nonce.
GCMParameterSpec
,
AlgorithmParametersSpi
Constructor and Description |
---|
GCMParameters()
The default constructor.
|
GCMParameters(byte[] aad,
byte[] nonce,
byte[] macBlock,
int macLength)
Creates GCM Parameters with the given additional data, IV, MAC length and MAC block.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
engineGetEncoded()
Returns the parameters as DER byte array.
|
protected byte[] |
engineGetEncoded(java.lang.String format)
Returns the parameters as a DER byte array.
|
protected java.security.spec.AlgorithmParameterSpec |
engineGetParameterSpec(java.lang.Class paramSpec)
Returns a GCM Parameter Specification of this GCM Parameters object.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec paramSpec)
Initializes this parameters object using the parameters specified in paramSpec.
|
protected void |
engineInit(byte[] params)
Initializes this GCMParameters object from the given DER encoded byte array.
|
protected void |
engineInit(byte[] params,
java.lang.String format)
Inits the parameters from an DER encoded byte array.
|
protected java.lang.String |
engineToString()
Returns a formatted string describing the GCM Parameters.
|
public GCMParameters() throws java.security.InvalidAlgorithmParameterException
AlgorithmParameters.getInstance
for obtaining a GCMParameters object.java.security.InvalidAlgorithmParameterException
- if the parameter values are incorrectpublic GCMParameters(byte[] aad, byte[] nonce, byte[] macBlock, int macLength) throws java.security.InvalidAlgorithmParameterException
aad
- the additional data that is authenticatednonce
- the nonce to generate the IVmacLength
- number of bytes used for authenticationmacBlock
- the authentication blockjava.security.InvalidAlgorithmParameterException
- if the parameter values are incorrectprotected byte[] engineGetEncoded() throws java.io.IOException
engineGetEncoded
in class java.security.AlgorithmParametersSpi
java.io.IOException
- if an encoding error occursprotected byte[] engineGetEncoded(java.lang.String format) throws java.io.IOException
Format is ignored. Only DER encoding is supported at this time. This method
only calls engineGetEncoded()
, regardless of what
is specified in the format
string.
engineGetEncoded
in class java.security.AlgorithmParametersSpi
format
- the encoding format; ignoredjava.io.IOException
- if an encoding error occursprotected java.security.spec.AlgorithmParameterSpec engineGetParameterSpec(java.lang.Class paramSpec) throws java.security.spec.InvalidParameterSpecException
GCMParameterSpec
than a InvalidParameterSpecException
is thrown.engineGetParameterSpec
in class java.security.AlgorithmParametersSpi
paramSpec
- the specification class in which the parameters should be returned
- has to be the class GCMParameterSpec
java.security.spec.InvalidParameterSpecException
- if the requested parameter specification is inappropriate
for this parameter object.protected void engineInit(java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.spec.InvalidParameterSpecException
engineInit
in class java.security.AlgorithmParametersSpi
paramSpec
- the parameter specification - must be GCMParameterSpec
.java.security.spec.InvalidParameterSpecException
- if the given parameter specification is
inappropriate for the initialization of this parameter object.protected void engineInit(byte[] params) throws java.io.IOException
engineInit
in class java.security.AlgorithmParametersSpi
params
- the DER encoded byte arrayjava.io.IOException
- if an error occurs when decoding the given byte array or
the derived parameter values are invalidprotected void engineInit(byte[] params, java.lang.String format) throws java.io.IOException
engineInit(params)
for initializing this GCMParameters
object from the given DER encoded byte array, regardless of what is specified
in the format
string.
engineInit
in class java.security.AlgorithmParametersSpi
params
- the DER encoded byte arrayformat
- the encoding format; ignoredjava.io.IOException
- if an error occurs when decoding the given byte arrayprotected java.lang.String engineToString()
engineToString
in class java.security.AlgorithmParametersSpi