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 the getInstance static factory method on the AlgorithmParameters 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 the Provider 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 an AlgorithmParameters object is instantiated, it must be initialized using a call to init, with an appropriate parameter specification or parameter encoding:
void init(AlgorithmParameterSpec paramSpec)
void init(byte[] params)
void init(byte[] params, String format)
In these init methods, params is an array containing the encoded parameters, and format is the name of the decoding format. In the init method with a params argument but no format 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 an AlgorithmParameters object can be obtained using a call to getEncoded:
byte[] getEncoded()
This 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.
If you want the parameters returned in a specified encoding format, use
byte[] getEncoded(String format)
If format is null, the primary encoding format for parameters is used, as in the other getEncoded method.
Note: In most AlgorithmParameters implementations, supplied by the IBMJCE provider, the format 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 to getParameterSpec:
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 the DSAParameterSpec class. (This class is in the java.security.spec package.)