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
AlgorithmParametersObject - As with all engine classes, the way to get an
AlgorithmParametersobject for a particular type of algorithm is to call thegetInstancestatic factory method on theAlgorithmParametersclass:static AlgorithmParameters getInstance(String algorithm)Note: The algorithm name is not case-sensitive.A caller can optionally specify the name of a provider or theProviderclass, 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
AlgorithmParametersObject - After anIn these
AlgorithmParametersobject 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)initmethods,paramsis an array containing the encoded parameters, andformatis the name of the decoding format. In theinitmethod with aparamsargument but noformatargument, 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:AlgorithmParametersobjects 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.
AlgorithmParametersobject can be obtained using a call togetEncoded:byte[] getEncoded()If you want the parameters returned in a specified encoding format, useIfbyte[] getEncoded(String format)formatis null, the primary encoding format for parameters is used, as in the othergetEncodedmethod.Note: In mostAlgorithmParametersimplementations, supplied by the IBMJCE provider, theformatargument is currently ignored. - Converting an
AlgorithmParametersObject to a Transparent Specification - A transparent parameter specification for the algorithm parameters can be obtained from an
AlgorithmParametersobject using a call togetParameterSpec:AlgorithmParameterSpec getParameterSpec(Class paramSpec)paramSpecidentifies the specification class in which the parameters should be returned. The specification class could be, for example,DSAParameterSpec.classto indicate that the parameters should be returned in an instance of theDSAParameterSpecclass. (This class is in thejava.security.specpackage.)