Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Protected Ctors](https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#proctors) \| [Methods](https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#inhmethods)

# AlgorithmParameterGenerator


`
public


class
AlgorithmParameterGenerator
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.security.AlgorithmParameterGenerator |

<br />

*** ** * ** ***

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:

- The algorithm-independent approach uses the fact that all parameter generators share the concept of a "size" and a source of randomness. The measure of size is universally shared by all algorithm parameters, though it is interpreted differently for different algorithms. For example, in the case of parameters for the *DSA* algorithm, "size" corresponds to the size of the prime modulus (in bits). When using this approach, algorithm-specific parameter generation values - if any - default to some standard values, unless they can be derived from the specified size.
- The other approach initializes a parameter generator object using algorithm-specific semantics, which are represented by a set of algorithm-specific parameter generation values. To generate Diffie-Hellman system parameters, for example, the parameter generation values usually consist of the size of the prime modulus and the size of the random exponent, both specified in number of bits.

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.
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.

Android provides the following `AlgorithmParameterGenerator` algorithms:

| Algorithm | Supported API Levels |
|---|---|
| AES | 1-8 |
| DES | 1-8 |
| DESede | 1-8 |
| DH | 1+ |
| DSA | 1+ |

<br />

**See also:**

- `https://developer.android.com/reference/java/security/AlgorithmParameters`
- `https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec`

## Summary

| ### Protected constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#AlgorithmParameterGenerator(java.security.AlgorithmParameterGeneratorSpi,%20java.security.Provider,%20java.lang.String)(https://developer.android.com/reference/java/security/AlgorithmParameterGeneratorSpi paramGenSpi, https://developer.android.com/reference/java/security/Provider provider, https://developer.android.com/reference/java/lang/String algorithm) ` Creates an AlgorithmParameterGenerator object. |

| ### Public methods ||
|---|---|
| ` final https://developer.android.com/reference/java/security/AlgorithmParameters` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#generateParameters()() ` Generates the parameters. |
| ` final https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#getAlgorithm()() ` Returns the standard name of the algorithm this parameter generator is associated with. |
| ` static https://developer.android.com/reference/java/security/AlgorithmParameterGenerator` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#getInstance(java.lang.String)(https://developer.android.com/reference/java/lang/String algorithm) ` Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm. |
| ` static https://developer.android.com/reference/java/security/AlgorithmParameterGenerator` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#getInstance(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String algorithm, https://developer.android.com/reference/java/lang/String provider) ` Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm. |
| ` static https://developer.android.com/reference/java/security/AlgorithmParameterGenerator` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#getInstance(java.lang.String,%20java.security.Provider)(https://developer.android.com/reference/java/lang/String algorithm, https://developer.android.com/reference/java/security/Provider provider) ` Returns an AlgorithmParameterGenerator object for generating a set of parameters to be used with the specified algorithm. |
| ` final https://developer.android.com/reference/java/security/Provider` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#getProvider()() ` Returns the provider of this algorithm parameter generator object. |
| ` final void` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec,%20java.security.SecureRandom)(https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec genParamSpec, https://developer.android.com/reference/java/security/SecureRandom random) ` Initializes this parameter generator with a set of algorithm-specific parameter generation values. |
| ` final void` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#init(int)(int size) ` Initializes this parameter generator for a certain size. |
| ` final void` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#init(int,%20java.security.SecureRandom)(int size, https://developer.android.com/reference/java/security/SecureRandom random) ` Initializes this parameter generator for a certain size and source of randomness. |
| ` final void` | ` https://developer.android.com/reference/java/security/AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec)(https://developer.android.com/reference/java/security/spec/AlgorithmParameterSpec genParamSpec) ` Initializes this parameter generator with a set of algorithm-specific parameter generation values. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Protected constructors

### AlgorithmParameterGenerator

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected AlgorithmParameterGenerator (AlgorithmParameterGeneratorSpi paramGenSpi, 
                Provider provider, 
                String algorithm)
```

Creates an AlgorithmParameterGenerator object.

<br />

| Parameters ||
|---|---|
| `paramGenSpi` | `AlgorithmParameterGeneratorSpi`: the delegate <br /> |
| `provider` | `Provider`: the provider <br /> |
| `algorithm` | `String`: the algorithm <br /> |

## Public methods

### generateParameters

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final AlgorithmParameters generateParameters ()
```

Generates the parameters.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/AlgorithmParameters` | the new AlgorithmParameters object. <br /> |

### getAlgorithm

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final String getAlgorithm ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the string name of the algorithm. <br /> |

### getInstance

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static AlgorithmParameterGenerator getInstance (String algorithm)
```

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 `https://developer.android.com/reference/java/security/Security#getProviders()` method.

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: the name of the algorithm this parameter generator is associated with.cc <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/AlgorithmParameterGenerator` | the new `AlgorithmParameterGenerator` object <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `algorithm` is `null` on Android 14 or above |
| `https://developer.android.com/reference/java/security/NoSuchAlgorithmException` | if no `Provider` supports an `AlgorithmParameterGeneratorSpi` implementation for the specified algorithm |

**See also:**

- `https://developer.android.com/reference/java/security/Provider`

### getInstance

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static AlgorithmParameterGenerator getInstance (String algorithm, 
                String provider)
```

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 `https://developer.android.com/reference/java/security/Security#getProviders()` method.

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: the name of the algorithm this parameter generator is associated with. <br /> |
| `provider` | `String`: the string name of the Provider. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/AlgorithmParameterGenerator` | the new `AlgorithmParameterGenerator` object <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the provider name is `null` or empty |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `algorithm` is `null` on Android 14 or above |
| `https://developer.android.com/reference/java/security/NoSuchAlgorithmException` | if an `AlgorithmParameterGeneratorSpi` implementation for the specified algorithm is not available from the specified provider |
| `https://developer.android.com/reference/java/security/NoSuchProviderException` | if the specified provider is not registered in the security provider list |

**See also:**

- `https://developer.android.com/reference/java/security/Provider`

### getInstance

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static AlgorithmParameterGenerator getInstance (String algorithm, 
                Provider provider)
```

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
object is returned. Note that the specified Provider object
does not have to be registered in the provider list.

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: the string name of the algorithm this parameter generator is associated with. <br /> |
| `provider` | `Provider`: the `Provider` object. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/AlgorithmParameterGenerator` | the new `AlgorithmParameterGenerator` object <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the specified provider is `null` |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `algorithm` is `null` on Android 14 or above |
| `https://developer.android.com/reference/java/security/NoSuchAlgorithmException` | if an `AlgorithmParameterGeneratorSpi` implementation for the specified algorithm is not available from the specified `Provider` object |

**See also:**

- `https://developer.android.com/reference/java/security/Provider`

### getProvider

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final Provider getProvider ()
```

Returns the provider of this algorithm parameter generator object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/security/Provider` | the provider of this algorithm parameter generator object <br /> |

### init

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void init (AlgorithmParameterSpec genParamSpec, 
                SecureRandom random)
```

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

<br />

| Parameters ||
|---|---|
| `genParamSpec` | `AlgorithmParameterSpec`: the set of algorithm-specific parameter generation values. <br /> |
| `random` | `SecureRandom`: the source of randomness. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/InvalidAlgorithmParameterException` | if the given parameter generation values are inappropriate for this parameter generator. |

### init

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.)

<br />

| Parameters ||
|---|---|
| `size` | `int`: the size (number of bits). <br /> |

### init

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void init (int size, 
                SecureRandom random)
```

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

<br />

| Parameters ||
|---|---|
| `size` | `int`: the size (number of bits). <br /> |
| `random` | `SecureRandom`: the source of randomness. <br /> |

### init

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void init (AlgorithmParameterSpec genParamSpec)
```

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.)

<br />

| Parameters ||
|---|---|
| `genParamSpec` | `AlgorithmParameterSpec`: the set of algorithm-specific parameter generation values. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/security/InvalidAlgorithmParameterException` | if the given parameter generation values are inappropriate for this parameter generator. |