Skip to content

Most visited

Recently visited

navigation
Added in API level 1

KeyGenerator

public class KeyGenerator
extends Object

java.lang.Object
   ↳ javax.crypto.KeyGenerator


This class provides the public API for generating symmetric cryptographic keys.

Summary

Protected constructors

KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider, String algorithm)

Creates a new KeyGenerator instance.

Public methods

final SecretKey generateKey()

Generates a secret key.

final String getAlgorithm()

Returns the name of the key generation algorithm.

final static KeyGenerator getInstance(String algorithm, String provider)

Creates a new KeyGenerator instance that provides the specified key algorithm from the specified provider.

final static KeyGenerator getInstance(String algorithm, Provider provider)

Creates a new KeyGenerator instance that provides the specified key algorithm from the specified provider.

final static KeyGenerator getInstance(String algorithm)

Creates a new KeyGenerator instance that provides the specified key algorithm,

final Provider getProvider()

Returns the provider of this KeyGenerator instance.

final void init(AlgorithmParameterSpec params, SecureRandom random)

Initializes this KeyGenerator instance with the specified algorithm parameters and randomness source.

final void init(AlgorithmParameterSpec params)

Initializes this KeyGenerator instance with the specified algorithm parameters.

final void init(SecureRandom random)

Initializes this KeyGenerator with the specified randomness source.

final void init(int keysize, SecureRandom random)

Initializes this KeyGenerator instance for the specified key size (in bits) using the specified randomness source.

final void init(int keysize)

Initializes this KeyGenerator instance for the specified key size (in bits).

Inherited methods

From class java.lang.Object

Protected constructors

KeyGenerator

Added in API level 1
KeyGenerator (KeyGeneratorSpi keyGenSpi, 
                Provider provider, 
                String algorithm)

Creates a new KeyGenerator instance.

Parameters
keyGenSpi KeyGeneratorSpi: the implementation delegate.
provider Provider: the implementation provider.
algorithm String: the name of the algorithm.

Public methods

generateKey

Added in API level 1
SecretKey generateKey ()

Generates a secret key.

Returns
SecretKey the generated secret key.

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the name of the key generation algorithm.

Returns
String the name of the key generation algorithm.

getInstance

Added in API level 1
KeyGenerator getInstance (String algorithm, 
                String provider)

Creates a new KeyGenerator instance that provides the specified key algorithm from the specified provider.

Parameters
algorithm String: the name of the requested key algorithm.
provider String: the name of the provider that is providing the algorithm.
Returns
KeyGenerator the new KeyGenerator instance.
Throws
NoSuchAlgorithmException if the specified algorithm is not provided by the specified provider.
NoSuchProviderException if the specified provider is not available.
IllegalArgumentException if the specified provider is name is null or empty.
NullPointerException if the specified algorithm name is null.

getInstance

Added in API level 1
KeyGenerator getInstance (String algorithm, 
                Provider provider)

Creates a new KeyGenerator instance that provides the specified key algorithm from the specified provider. The provider supplied does not have to be registered.

Parameters
algorithm String: the name of the requested key algorithm.
provider Provider: the provider that is providing the algorithm
Returns
KeyGenerator the new KeyGenerator instance.
Throws
NoSuchAlgorithmException if the specified algorithm is not provided by the specified provider.
IllegalArgumentException if the specified provider is null.
NullPointerException if the specified algorithm name is null.

getInstance

Added in API level 1
KeyGenerator getInstance (String algorithm)

Creates a new KeyGenerator instance that provides the specified key algorithm,

Parameters
algorithm String: the name of the requested key algorithm
Returns
KeyGenerator the new KeyGenerator instance.
Throws
NoSuchAlgorithmException if the specified algorithm is not available by any provider.
NullPointerException if algorithm is null.

getProvider

Added in API level 1
Provider getProvider ()

Returns the provider of this KeyGenerator instance.

Returns
Provider the provider of this KeyGenerator instance.

init

Added in API level 1
void init (AlgorithmParameterSpec params, 
                SecureRandom random)

Initializes this KeyGenerator instance with the specified algorithm parameters and randomness source.

Parameters
params AlgorithmParameterSpec: the parameters for the key generation algorithm.
random SecureRandom: the randomness source for any random bytes.
Throws
InvalidAlgorithmParameterException if the parameters cannot be uses to initialize this key generator algorithm.

init

Added in API level 1
void init (AlgorithmParameterSpec params)

Initializes this KeyGenerator instance with the specified algorithm parameters.

Parameters
params AlgorithmParameterSpec: the parameters for the key generation algorithm.
Throws
InvalidAlgorithmParameterException if the parameters cannot be used to initialize this key generator algorithm.

init

Added in API level 1
void init (SecureRandom random)

Initializes this KeyGenerator with the specified randomness source.

Parameters
random SecureRandom: the randomness source for any random bytes.

init

Added in API level 1
void init (int keysize, 
                SecureRandom random)

Initializes this KeyGenerator instance for the specified key size (in bits) using the specified randomness source.

Parameters
keysize int: the size of the key (in bits).
random SecureRandom: the randomness source for any random bytes.

init

Added in API level 1
void init (int keysize)

Initializes this KeyGenerator instance for the specified key size (in bits).

Parameters
keysize int: the size of the key (in bits).
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.