public class MGF1Parameters extends PKCS1AlgorithmParameters
MGF1
mask generation
function.
According to PKCS#1v2.1 the only parameter used by MGF1 is the algorithm id of the hash algorithm (default SHA-1) to be used:
mgf1SHA1 MaskGenAlgorithm ::= { algorithm id-mgf1, parameters HashAlgorithm : sha1 }MGF1Parameters can be generated provider independently by calling one of the
AlgorithmParameters.getInstance
methods. Subsequently the new
AlgorithmParameters object must be initialized with a proper MGF1 parameter
specification or a DER encoded byte array, e.g.:
MGF1ParameterSpec paramSpec = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("MGF1", "IAIK"); params.init(paramSpec);respectively:
byte[] encodedParams = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("MGF1", "IAIK"); params.init(encodedParams);
For obtaining MGF1 parameters in transparent representation from an opaque
MGF1Parameters object, the getParameterSpec
method can be used;
for obtaining the parameters as DER encoded ASN.1 object, use
getEncoded
:
MGF1ParameterSpec paramSpec = (MGF1ParameterSpec) params .getParameterSpec(MGF1ParameterSpec.class);respectively
byte[] encodedParams = params.getEncoded();
MGF1ParameterSpec
,
AlgorithmParameters
Constructor and Description |
---|
MGF1Parameters()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
decode(ASN1Object asn1Params)
Initializes this MGF1Parameters object from the given ASN1Object.
|
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 the MGF1 parameters as transparent parameter specification of the
given class type.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec paramSpec)
Initializes this MGF1Parameters from the given MGF1ParameterSpec.
|
protected void |
engineInit(byte[] params)
Initializes this MGF1Parameters 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 String representation of this object.
|
ASN1Object |
toASN1Object()
Gets an ASN.1 representation of this MGF1 parameters.
|
public MGF1Parameters()
MGF1Parameters
object. Applications shall use one of the
AlgorithmParameters.getInstance
factory methods for obtaining
MGF1Parameters.protected 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 occurspublic ASN1Object toASN1Object()
protected java.security.spec.AlgorithmParameterSpec engineGetParameterSpec(java.lang.Class paramSpec) throws java.security.spec.InvalidParameterSpecException
engineGetParameterSpec
in class java.security.AlgorithmParametersSpi
paramSpec
- the desired parameter specification class (MGF1ParameterSpec)java.security.spec.InvalidParameterSpecException
- if the parameters cannot be converted to the desired parameter
specificationprotected void engineInit(java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.spec.InvalidParameterSpecException
engineInit
in class PKCS1AlgorithmParameters
paramSpec
- the parameter specification, which has to be a MGF1ParameterSpecjava.security.spec.InvalidParameterSpecException
- if the given parameter specification is not a or is an invalid
MGF1ParameterSpecprotected void engineInit(byte[] params) throws java.io.IOException
engineInit
in class PKCS1AlgorithmParameters
params
- the DER encoded byte arrayjava.io.IOException
- if an error occurs when decoding the given byte arraypublic void decode(ASN1Object asn1Params) throws CodingException
asn1Params
- the MGF1 parameters in ASN.1 representationCodingException
- if an error occurs when parsing the parametersprotected void engineInit(byte[] params, java.lang.String format) throws java.io.IOException
engineInit(params)
for initializing this
MGF1Parameters 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