Top Description Fields Constructors Methods
java.security

public Class AlgorithmParameterGenerator

extends Object
Class Inheritance
Imports
java.security.spec.AlgorithmParameterSpec, java.util.Objects, sun.security.jca.JCAUtil

The AlgorithmParameterGenerator class is used to generate a set of parameters to be used with a certain algorithm. Parameter generators are constructed using the getInstance factory methods (static methods that return instances of a given class).

The object that will generate the parameters can be initialized in two different ways: in an algorithm-independent manner, or in an algorithm-specific manner:

In case the client does not explicitly initialize the AlgorithmParameterGenerator (via a call to an init method), each provider must supply (and document) a default initialization. See the Keysize Restriction sections of the JDK Providers document for information on the AlgorithmParameterGenerator defaults used by JDK providers. However, note that defaults may vary across different providers. Additionally, the default value for a provider may change in a future version. Therefore, it is recommended to explicitly initialize the AlgorithmParameterGenerator instead of relying on provider-specific defaults.

Every implementation of the Java platform is required to support the following standard AlgorithmParameterGenerator algorithms and keysizes in parentheses:

These algorithms are described in the AlgorithmParameterGenerator section of the Java Security Standard Algorithm Names Specification. Consult the release documentation for your implementation to see if any other algorithms are supported.
Author
Jan Luehe
Since
1.2
See Also
AlgorithmParameters, java.security.spec.AlgorithmParameterSpec

Field Summary

Modifier and TypeField and Description
private final String
private final AlgorithmParameterGeneratorSpi
private final Provider

Constructor Summary

AccessConstructor and Description
protected
AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi
the delegate
paramGenSpi
,
Provider
the provider
provider
,
String
the algorithm
algorithm
)

Creates an AlgorithmParameterGenerator object.

Method Summary

Modifier and TypeMethod and Description
public final AlgorithmParameters

Returns:

the new AlgorithmParameters object.
generateParameters
()

Generates the parameters.

public final String

Returns:

the string name of the algorithm.
getAlgorithm
()

Returns the standard name of the algorithm this parameter generator is associated with.

public static AlgorithmParameterGenerator

Returns:

the new AlgorithmParameterGenerator object
getInstance
(String
the name of the algorithm this parameter generator is associated with. See the AlgorithmParameterGenerator section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names.
algorithm
)

Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.

public static AlgorithmParameterGenerator

Returns:

the new AlgorithmParameterGenerator object
getInstance
(String
the name of the algorithm this parameter generator is associated with. See the AlgorithmParameterGenerator section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names.
algorithm
,
String
the string name of the Provider.
provider
)

Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.

public static AlgorithmParameterGenerator

Returns:

the new AlgorithmParameterGenerator object
getInstance
(String
the string name of the algorithm this parameter generator is associated with. See the AlgorithmParameterGenerator section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names.
algorithm
,
Provider
the Provider object.
provider
)

Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.

public final Provider

Returns:

the provider of this algorithm parameter generator object
getProvider
()

Returns the provider of this algorithm parameter generator object.

public final void
init(int
the size (number of bits).
size
)

Initializes this parameter generator for a certain size.

public final void
init(int
the size (number of bits).
size
,
SecureRandom
the source of randomness.
random
)

Initializes this parameter generator for a certain size and source of randomness.

public final void
init(AlgorithmParameterSpec
the set of algorithm-specific parameter generation values.
genParamSpec
)

Initializes this parameter generator with a set of algorithm-specific parameter generation values.

public final void
init(AlgorithmParameterSpec
the set of algorithm-specific parameter generation values.
genParamSpec
,
SecureRandom
the source of randomness.
random
)

Initializes this parameter generator with a set of algorithm-specific parameter generation values.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private final String algorithm
paramGenSpiback to summary
private final AlgorithmParameterGeneratorSpi paramGenSpi
providerback to summary
private final Provider provider

Constructor Detail

AlgorithmParameterGeneratorback to summary
protected AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi paramGenSpi, Provider provider, String algorithm)

Creates an AlgorithmParameterGenerator object.

Parameters
paramGenSpi:AlgorithmParameterGeneratorSpi

the delegate

provider:Provider

the provider

algorithm:String

the algorithm

Method Detail

generateParametersback to summary
public final AlgorithmParameters generateParameters()

Generates the parameters.

Returns:AlgorithmParameters

the new AlgorithmParameters object.

getAlgorithmback to summary
public final String getAlgorithm()

Returns the standard name of the algorithm this parameter generator is associated with.

Returns:String

the string name of the algorithm.

getInstanceback to summary
public static AlgorithmParameterGenerator getInstance(String algorithm) throws NoSuchAlgorithmException

Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.

This method traverses the list of registered security providers, starting with the most preferred provider. A new AlgorithmParameterGenerator object encapsulating the AlgorithmParameterGeneratorSpi implementation from the first provider that supports the specified algorithm is returned.

Note that the list of registered providers may be retrieved via the Security.getProviders() method.

Implementation Note

The JDK Reference Implementation additionally uses the jdk.security.provider.preferred Security property to determine the preferred provider order for the specified algorithm. This may be different from the order of providers returned by Security.getProviders().

Parameters
algorithm:String

the name of the algorithm this parameter generator is associated with. See the AlgorithmParameterGenerator section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names.

Returns:AlgorithmParameterGenerator

the new AlgorithmParameterGenerator object

Exceptions
NoSuchAlgorithmException:
if no Provider supports an AlgorithmParameterGeneratorSpi implementation for the specified algorithm
NullPointerException:
if algorithm is null
See Also
Provider
getInstanceback to summary
public static AlgorithmParameterGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException

Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.

A new AlgorithmParameterGenerator object encapsulating the AlgorithmParameterGeneratorSpi implementation from the specified provider is returned. The specified provider must be registered in the security provider list.

Note that the list of registered providers may be retrieved via the Security.getProviders() method.

Parameters
algorithm:String

the name of the algorithm this parameter generator is associated with. See the AlgorithmParameterGenerator section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names.

provider:String

the string name of the Provider.

Returns:AlgorithmParameterGenerator

the new AlgorithmParameterGenerator object

Exceptions
NoSuchAlgorithmException:
if an AlgorithmParameterGeneratorSpi implementation for the specified algorithm is not available from the specified provider
NoSuchProviderException:
if the specified provider is not registered in the security provider list
IllegalArgumentException:
if the provider name is null or empty
NullPointerException:
if algorithm is null
See Also
Provider
getInstanceback to summary
public static AlgorithmParameterGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException

Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm.

A new AlgorithmParameterGenerator object encapsulating the AlgorithmParameterGeneratorSpi implementation from the specified provider is returned. Note that the specified provider does not have to be registered in the provider list.

Parameters
algorithm:String

the string name of the algorithm this parameter generator is associated with. See the AlgorithmParameterGenerator section in the Java Security Standard Algorithm Names Specification for information about standard algorithm names.

provider:Provider

the Provider object.

Returns:AlgorithmParameterGenerator

the new AlgorithmParameterGenerator object

Exceptions
NoSuchAlgorithmException:
if an AlgorithmParameterGeneratorSpi implementation for the specified algorithm is not available from the specified Provider object
IllegalArgumentException:
if the specified provider is null
NullPointerException:
if algorithm is null
Since
1.4
See Also
Provider
getProviderback to summary
public final Provider getProvider()

Returns the provider of this algorithm parameter generator object.

Returns:Provider

the provider of this algorithm parameter generator object

initback to summary
public final void init(int size)

Initializes this parameter generator for a certain size. To create the parameters, the SecureRandom implementation of the highest-priority installed provider is used as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness is used.)

Parameters
size:int

the size (number of bits).

initback to summary
public final void init(int size, SecureRandom random)

Initializes this parameter generator for a certain size and source of randomness.

Parameters
size:int

the size (number of bits).

random:SecureRandom

the source of randomness.

initback to summary
public final void init(AlgorithmParameterSpec genParamSpec) throws InvalidAlgorithmParameterException

Initializes this parameter generator with a set of algorithm-specific parameter generation values. To generate the parameters, the SecureRandom implementation of the highest-priority installed provider is used as the source of randomness. (If none of the installed providers supply an implementation of SecureRandom, a system-provided source of randomness is used.)

Parameters
genParamSpec:AlgorithmParameterSpec

the set of algorithm-specific parameter generation values.

Exceptions
InvalidAlgorithmParameterException:
if the given parameter generation values are inappropriate for this parameter generator.
initback to summary
public final void init(AlgorithmParameterSpec genParamSpec, SecureRandom random) throws InvalidAlgorithmParameterException

Initializes this parameter generator with a set of algorithm-specific parameter generation values.

Parameters
genParamSpec:AlgorithmParameterSpec

the set of algorithm-specific parameter generation values.

random:SecureRandom

the source of randomness.

Exceptions
InvalidAlgorithmParameterException:
if the given parameter generation values are inappropriate for this parameter generator.