Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public abstract class

KeyPairGenerator

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

Class Overview

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.

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 .
[Expand]
Inherited Methods
From class java.security.KeyPairGeneratorSpi
From class java.lang.Object

Protected Constructors

protected KeyPairGenerator ( String algorithm)

Added in API level 1

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

Parameters
algorithm the name of algorithm to use

Public Methods

public final KeyPair genKeyPair ()

Added in API level 1

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

This does exactly the same as generateKeyPair() .

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

public KeyPair generateKeyPair ()

Added in API level 1

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

This does exactly the same as genKeyPair() .

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

public String getAlgorithm ()

Added in API level 1

Returns the name of the algorithm of this KeyPairGenerator .

Returns
  • the name of the algorithm of this KeyPairGenerator

public static KeyPairGenerator getInstance ( String algorithm, String provider)

Added in API level 1

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

Parameters
algorithm the name of the algorithm to use
provider the name of the provider
Returns
  • 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()

public static KeyPairGenerator getInstance ( String algorithm, Provider provider)

Added in API level 1

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

Parameters
algorithm the name of the algorithm to use
provider the provider
Returns
  • 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

public static KeyPairGenerator getInstance ( String algorithm)

Added in API level 1

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

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

public final Provider getProvider ()

Added in API level 1

Returns the provider associated with this KeyPairGenerator .

Returns
  • the provider associated with this KeyPairGenerator

public void initialize ( AlgorithmParameterSpec param)

Added in API level 1

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

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

public void initialize ( AlgorithmParameterSpec param, SecureRandom random)

Added in API level 1

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

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

public void initialize (int keysize)

Added in API level 1

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

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

public void initialize (int keysize, SecureRandom random)

Added in API level 1

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

Parameters
keysize the key size
random the source of randomness