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.
KeyPair,
AlgorithmParameterSpec| Modifier | Constructor and Description |
|---|---|
protected |
KeyPairGenerator(String algorithm)
Constructs a new instance of
KeyPairGenerator. |
| Modifier and Type | Method and Description |
|---|---|
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. |
cloneprotected KeyPairGenerator(String algorithm)
KeyPairGenerator.algorithm - the algorithm to use.public String getAlgorithm()
public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
KeyPairGenerator which generates
key-pairs for the specified algorithm.algorithm - the name of the algorithm to use.NoSuchAlgorithmException - if the algorithm is not implemented by any
provider.IllegalArgumentException - if algorithm is
null or is an empty string.public static KeyPairGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
KeyPairGenerator which generates
key-pairs for the specified algorithm from a named provider.algorithm - the name of the algorithm to use.provider - the name of a Provider to use.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.public static KeyPairGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
KeyPairGenerator which generates
key-pairs for the specified algorithm from a designated Provider.algorithm - the name of the algorithm to use.provider - the Provider to use.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.Providerpublic final Provider getProvider()
Provider of this instance.Provider of this instance.public void initialize(int keysize)
keysize - the size of keys to use.public void initialize(int keysize, SecureRandom random)
SecureRandom.initialize in class KeyPairGeneratorSpikeysize - the size of keys to use.random - the SecureRandom to use.public void initialize(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException
AlgorithmParameterSpec. Since no source of randomness is specified,
a default one will be used.params - the AlgorithmParameterSpec to use.InvalidAlgorithmParameterException - if the designated specifications are invalid.public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException
AlgorithmParameterSpec
and SecureRandom.initialize in class KeyPairGeneratorSpiparams - the AlgorithmParameterSpec to use.random - the SecureRandom to use.InvalidAlgorithmParameterException - if the designated specifications are invalid.public final KeyPair genKeyPair()
KeyPair from the "GNU" security provider.
This method generates a unique key-pair each time it is called.
KeyPair.generateKeyPair()public KeyPair generateKeyPair()
KeyPair from the "GNU" security provider.
This method generates a unique key pair each time it is called.
generateKeyPair in class KeyPairGeneratorSpiKeyPair.genKeyPair()