java.security

Class 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
KeyPairgenerateKeyPair()
Generates a new "DSA" {@link KeyPair} from the "GNU" security provider.
KeyPairgenKeyPair()
Generates a new "DSA" {@link KeyPair} from the "GNU" security provider.
StringgetAlgorithm()
Returns the name of the algorithm used.
static KeyPairGeneratorgetInstance(String algorithm)
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm.
static KeyPairGeneratorgetInstance(String algorithm, String provider)
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a named provider.
static KeyPairGeneratorgetInstance(String algorithm, Provider provider)
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a designated {@link Provider}.
ProvidergetProvider()
Returns the {@link Provider} of this instance.
voidinitialize(int keysize)
Initializes this instance for the specified key size.
voidinitialize(int keysize, SecureRandom random)
Initializes this instance for the specified key size and {@link SecureRandom}.
voidinitialize(AlgorithmParameterSpec params)
Initializes this instance with the specified {@link AlgorithmParameterSpec}.
voidinitialize(AlgorithmParameterSpec params, SecureRandom random)
Initializes this instance with the specified {@link AlgorithmParameterSpec} and {@link SecureRandom}.

Constructor Detail

KeyPairGenerator

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

Parameters: algorithm the algorithm to use.

Method Detail

generateKeyPair

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

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

Returns: a new unique {@link KeyPair}.

See Also: genKeyPair

genKeyPair

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

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

Returns: a new unique {@link KeyPair}.

Since: 1.2

See Also: generateKeyPair

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)
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)
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 {@link 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)
Returns a new instance of KeyPairGenerator which generates key-pairs for the specified algorithm from a designated {@link Provider}.

Parameters: algorithm the name of the algorithm to use. provider the {@link Provider} to use.

Returns: a new insatnce repesenting the desired algorithm.

Throws: NoSuchAlgorithmException if the algorithm is not implemented by the {@link 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 {@link Provider} of this instance.

Returns: the {@link 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 {@link SecureRandom}.

Parameters: keysize the size of keys to use. random the {@link SecureRandom} to use.

Since: 1.2

initialize

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

Parameters: params the {@link AlgorithmParameterSpec} to use.

Throws: InvalidAlgorithmParameterException if the designated specifications are invalid.

Since: 1.2

initialize

public void initialize(AlgorithmParameterSpec params, SecureRandom random)
Initializes this instance with the specified {@link AlgorithmParameterSpec} and {@link SecureRandom}.

Parameters: params the {@link AlgorithmParameterSpec} to use. random the {@link SecureRandom} to use.

Throws: InvalidAlgorithmParameterException if the designated specifications are invalid.

Since: 1.2