The AlgorithmParameters
Class
The AlgorithmParameters
class is an engine class that provides
an opaque representation of cryptographic parameters.
An opaque representation is one in which you have no direct
access to the parameter fields; you can get only the name of the algorithm
associated with the parameter set and some kind of encoding for the
parameter set. This method is in contrast to a transparent representation
of parameters, in which you can access each value individually, through
one of the get
methods defined in the corresponding specification class. Note that you can
call the AlgorithmParameters
getParameterSpec
method
to convert an AlgorithmParameters
object to a transparent
specification (see the following section).
- Creating an
AlgorithmParameters
Object - As with all engine classes, the way to get an
AlgorithmParameters
object for a particular type of algorithm is to call thegetInstance
static factory method on theAlgorithmParameters
class:static AlgorithmParameters getInstance(String algorithm)
Note: The algorithm name is not case-sensitive.A caller can optionally specify the name of a provider or theProvider
class, which will guarantee that the algorithm parameter implementation requested is from the named provider:static AlgorithmParameters getInstance(String algorithm, String provider) static AlgorithmParameters getInstance(String algorithm, Provider provider)
- Initializing an
AlgorithmParameters
Object - After anIn these
AlgorithmParameters
object is instantiated, it must be initialized using a call toinit
, with an appropriate parameter specification or parameter encoding:void init(AlgorithmParameterSpec paramSpec) void init(byte[] params) void init(byte[] params, String format)
init
methods,params
is an array containing the encoded parameters, andformat
is the name of the decoding format. In theinit
method with aparams
argument but noformat
argument, the primary decoding format for parameters is used. The primary decoding format is ASN.1, if an ASN.1 specification for the parameters exists.Note:AlgorithmParameters
objects can be initialized only once. They are not reusable. - Obtaining the Encoded Parameters
-
A byte encoding of the parameters represented in anThis method returns the parameters in their primary encoding format. The primary encoding format for parameters is ASN.1, if an ASN.1 specification for this type of parameters exists.
AlgorithmParameters
object can be obtained using a call togetEncoded
:byte[] getEncoded()
If you want the parameters returned in a specified encoding format, useIfbyte[] getEncoded(String format)
format
is null, the primary encoding format for parameters is used, as in the othergetEncoded
method.Note: In mostAlgorithmParameters
implementations, supplied by the IBMJCE provider, theformat
argument is currently ignored. - Converting an
AlgorithmParameters
Object to a Transparent Specification - A transparent parameter specification for the algorithm parameters can be obtained from an
AlgorithmParameters
object using a call togetParameterSpec
:AlgorithmParameterSpec getParameterSpec(Class paramSpec)
paramSpec
identifies the specification class in which the parameters should be returned. The specification class could be, for example,DSAParameterSpec.class
to indicate that the parameters should be returned in an instance of theDSAParameterSpec
class. (This class is in thejava.security.spec
package.)