java.security
Class KeyPairGenerator

java.lang.Object
  extended by java.security.KeyPairGeneratorSpi
      extended by java.security.KeyPairGenerator

public abstract class KeyPairGenerator
extends KeyPairGeneratorSpi

KeyPairGenerator is a class used to generate key-pairs for a security algorithm.

The KeyPairGenerator is created with the getInstance() Factory methods. It is used to generate a pair of public and private keys for a specific algorithm and associate this key-pair with the algorithm parameters it was initialized with.

See Also:
KeyPair, AlgorithmParameterSpec

Constructor Summary
protected KeyPairGenerator(String algorithm)
          Constructs a new instance of KeyPairGenerator.
 
Method Summary
 KeyPair generateKeyPair()
          Generates a new "DSA" KeyPair from the "GNU" security provider.
 KeyPair genKeyPair()
          Generates a new "DSA" KeyPair from the "GNU" security provider.
 String getAlgorithm()
          Returns the name of the algorithm used.
static KeyPairGenerator getInstance(String algorithm)
          Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm.
static KeyPairGenerator getInstance(String algorithm, Provider provider)
          Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a designated Provider.
static KeyPairGenerator getInstance(String algorithm, String provider)
          Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a named provider.
 Provider getProvider()
          Returns the Provider of this instance.
 void initialize(AlgorithmParameterSpec params)
          Initializes this instance with the specified AlgorithmParameterSpec.
 void initialize(AlgorithmParameterSpec params, SecureRandom random)
          Initializes this instance with the specified AlgorithmParameterSpec and SecureRandom.
 void initialize(int keysize)
          Initializes this instance for the specified key size.
 void initialize(int keysize, SecureRandom random)
          Initializes this instance for the specified key size and SecureRandom.
 
Methods inherited from class java.security.KeyPairGeneratorSpi
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyPairGenerator

protected KeyPairGenerator(String algorithm)
Constructs a new instance of KeyPairGenerator.

Parameters:
algorithm - the algorithm to use.
Method Detail

getAlgorithm

public String getAlgorithm()
Returns the name of the algorithm used.

Returns:
the name of the algorithm used.

getInstance

public static KeyPairGenerator getInstance(String algorithm)
                                    throws NoSuchAlgorithmException
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm.

Parameters:
algorithm - the name of the algorithm to use.
Returns:
a new instance repesenting the desired algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not implemented by any provider.
IllegalArgumentException - if algorithm is null or is an empty string.

getInstance

public static KeyPairGenerator getInstance(String algorithm,
                                           String provider)
                                    throws NoSuchAlgorithmException,
                                           NoSuchProviderException
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a named provider.

Parameters:
algorithm - the name of the algorithm to use.
provider - the name of a Provider to use.
Returns:
a new instance repesenting the desired algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not implemented by the named provider.
NoSuchProviderException - if the named provider was not found.
IllegalArgumentException - if either algorithm or provider is null or empty.

getInstance

public static KeyPairGenerator getInstance(String algorithm,
                                           Provider provider)
                                    throws NoSuchAlgorithmException
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a designated Provider.

Parameters:
algorithm - the name of the algorithm to use.
provider - the Provider to use.
Returns:
a new insatnce repesenting the desired algorithm.
Throws:
NoSuchAlgorithmException - if the algorithm is not implemented by the Provider.
IllegalArgumentException - if either algorithm or provider is null, or if algorithm is an empty string.
Since:
1.4
See Also:
Provider

getProvider

public final Provider getProvider()
Returns the Provider of this instance.

Returns:
the Provider of this instance.

initialize

public void initialize(int keysize)
Initializes this instance for the specified key size. Since no source of randomness is specified, a default one will be used.

Parameters:
keysize - the size of keys to use.

initialize

public void initialize(int keysize,
                       SecureRandom random)
Initializes this instance for the specified key size and SecureRandom.

Specified by:
initialize in class KeyPairGeneratorSpi
Parameters:
keysize - the size of keys to use.
random - the SecureRandom to use.
Since:
1.2

initialize

public void initialize(AlgorithmParameterSpec params)
                throws InvalidAlgorithmParameterException
Initializes this instance with the specified AlgorithmParameterSpec. Since no source of randomness is specified, a default one will be used.

Parameters:
params - the AlgorithmParameterSpec to use.
Throws:
InvalidAlgorithmParameterException - if the designated specifications are invalid.
Since:
1.2

initialize

public void initialize(AlgorithmParameterSpec params,
                       SecureRandom random)
                throws InvalidAlgorithmParameterException
Initializes this instance with the specified AlgorithmParameterSpec and SecureRandom.

Overrides:
initialize in class KeyPairGeneratorSpi
Parameters:
params - the AlgorithmParameterSpec to use.
random - the SecureRandom to use.
Throws:
InvalidAlgorithmParameterException - if the designated specifications are invalid.
Since:
1.2

genKeyPair

public final KeyPair genKeyPair()
Generates a new "DSA" KeyPair from the "GNU" security provider.

This method generates a unique key-pair each time it is called.

Returns:
a new unique KeyPair.
Since:
1.2
See Also:
generateKeyPair()

generateKeyPair

public KeyPair generateKeyPair()
Generates a new "DSA" KeyPair from the "GNU" security provider.

This method generates a unique key pair each time it is called.

Specified by:
generateKeyPair in class KeyPairGeneratorSpi
Returns:
a new unique KeyPair.
See Also:
genKeyPair()