Skip to content

Most visited

Recently visited

navigation
Added in API level 1

KeyPairGenerator

public abstract class KeyPairGenerator
extends KeyPairGeneratorSpi

java.lang.Object
   ↳ java.security.KeyPairGeneratorSpi
     ↳ java.security.KeyPairGenerator


KeyPairGenerator is an engine class which is capable of generating a private key and its related public key utilizing the algorithm it was initialized with.

See also:

Summary

Protected constructors

KeyPairGenerator(String algorithm)

Constructs a new instance of KeyPairGenerator with the name of the algorithm to use.

Public methods

final KeyPair genKeyPair()

Computes and returns a new unique KeyPair each time this method is called.

KeyPair generateKeyPair()

Computes and returns a new unique KeyPair each time this method is called.

String getAlgorithm()

Returns the name of the algorithm of this KeyPairGenerator.

static KeyPairGenerator getInstance(String algorithm, String provider)

Returns a new instance of KeyPairGenerator that utilizes the specified algorithm from the specified provider.

static KeyPairGenerator getInstance(String algorithm, Provider provider)

Returns a new instance of KeyPairGenerator that utilizes the specified algorithm from the specified provider.

static KeyPairGenerator getInstance(String algorithm)

Returns a new instance of KeyPairGenerator that utilizes the specified algorithm.

final Provider getProvider()

Returns the provider associated with this KeyPairGenerator.

void initialize(AlgorithmParameterSpec param)

Initializes this KeyPairGenerator with the given AlgorithmParameterSpec.

void initialize(AlgorithmParameterSpec param, SecureRandom random)

Initializes this KeyPairGenerator with the given AlgorithmParameterSpec and the given SecureRandom.

void initialize(int keysize)

Initializes this KeyPairGenerator with the given key size.

void initialize(int keysize, SecureRandom random)

Initializes this KeyPairGenerator with the given key size and the given SecureRandom.

Inherited methods

From class java.security.KeyPairGeneratorSpi
From class java.lang.Object

Protected constructors

KeyPairGenerator

Added in API level 1
KeyPairGenerator (String algorithm)

Constructs a new instance of KeyPairGenerator with the name of the algorithm to use.

Parameters
algorithm String: the name of algorithm to use

Public methods

genKeyPair

Added in API level 1
KeyPair genKeyPair ()

Computes and returns a new unique KeyPair each time this method is called.

This does exactly the same as generateKeyPair().

Returns
KeyPair a new unique KeyPair each time this method is called

generateKeyPair

Added in API level 1
KeyPair generateKeyPair ()

Computes and returns a new unique KeyPair each time this method is called.

This does exactly the same as genKeyPair().

Returns
KeyPair a new unique KeyPair each time this method is called

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the name of the algorithm of this KeyPairGenerator.

Returns
String the name of the algorithm of this KeyPairGenerator

getInstance

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

Returns a new instance of KeyPairGenerator that utilizes the specified algorithm from the specified provider.

Parameters
algorithm String: the name of the algorithm to use
provider String: the name of the provider
Returns
KeyPairGenerator a new instance of KeyPairGenerator that utilizes the specified algorithm from the specified provider
Throws
NoSuchAlgorithmException if the specified algorithm is not available
NoSuchProviderException if the specified provider is not available
NullPointerException if algorithm is null
IllegalArgumentException if provider == null || provider.isEmpty()

getInstance

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

Returns a new instance of KeyPairGenerator that utilizes the specified algorithm from the specified provider. The provider supplied does not have to be registered.

Parameters
algorithm String: the name of the algorithm to use
provider Provider: the provider
Returns
KeyPairGenerator a new instance of KeyPairGenerator that utilizes the specified algorithm from the specified provider
Throws
NoSuchAlgorithmException if the specified algorithm is not available
NullPointerException if algorithm is null
IllegalArgumentException if provider == null

getInstance

Added in API level 1
KeyPairGenerator getInstance (String algorithm)

Returns a new instance of KeyPairGenerator that utilizes the specified algorithm.

Parameters
algorithm String: the name of the algorithm to use
Returns
KeyPairGenerator a new instance of KeyPairGenerator that utilizes the specified algorithm
Throws
NoSuchAlgorithmException if the specified algorithm is not available
NullPointerException if algorithm is null

getProvider

Added in API level 1
Provider getProvider ()

Returns the provider associated with this KeyPairGenerator.

Returns
Provider the provider associated with this KeyPairGenerator

initialize

Added in API level 1
void initialize (AlgorithmParameterSpec param)

Initializes this KeyPairGenerator with the given AlgorithmParameterSpec. A default SecureRandom instance will be used.

Parameters
param AlgorithmParameterSpec: the parameters to use
Throws
InvalidAlgorithmParameterException if the specified parameters are not supported

initialize

Added in API level 1
void initialize (AlgorithmParameterSpec param, 
                SecureRandom random)

Initializes this KeyPairGenerator with the given AlgorithmParameterSpec and the given SecureRandom.

Parameters
param AlgorithmParameterSpec: the parameters to use
random SecureRandom: the source of randomness
Throws
InvalidAlgorithmParameterException if the specified parameters are not supported

initialize

Added in API level 1
void initialize (int keysize)

Initializes this KeyPairGenerator with the given key size. The default parameter set and a default SecureRandom instance will be used.

Parameters
keysize int: the size of the key (number of bits)

initialize

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

Initializes this KeyPairGenerator with the given key size and the given SecureRandom. The default parameter set will be used.

Parameters
keysize int: the key size
random SecureRandom: the source of randomness
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.