Package java.security
Class KeyPairGenerator
- java.lang.Object
-
- java.security.KeyPairGeneratorSpi
-
- java.security.KeyPairGenerator
-
- Direct Known Subclasses:
KeyPairGeneratorSpi,KeyPairGeneratorSpi,KeyPairGeneratorSpi,KeyPairGeneratorSpi,OpenSSLECKeyPairGenerator
public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
KeyPairGeneratoris 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:
KeyPairGeneratorSpi
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedKeyPairGenerator(String algorithm)Constructs a new instance ofKeyPairGeneratorwith the name of the algorithm to use.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyPairgenerateKeyPair()Computes and returns a new uniqueKeyPaireach time this method is called.KeyPairgenKeyPair()Computes and returns a new uniqueKeyPaireach time this method is called.StringgetAlgorithm()Returns the name of the algorithm of thisKeyPairGenerator.static KeyPairGeneratorgetInstance(String algorithm)Returns a new instance ofKeyPairGeneratorthat utilizes the specified algorithm.static KeyPairGeneratorgetInstance(String algorithm, String provider)Returns a new instance ofKeyPairGeneratorthat utilizes the specified algorithm from the specified provider.static KeyPairGeneratorgetInstance(String algorithm, Provider provider)Returns a new instance ofKeyPairGeneratorthat utilizes the specified algorithm from the specified provider.ProvidergetProvider()Returns the provider associated with thisKeyPairGenerator.voidinitialize(int keysize)Initializes thisKeyPairGeneratorwith the given key size.voidinitialize(int keysize, SecureRandom random)Initializes thisKeyPairGeneratorwith the given key size and the givenSecureRandom.voidinitialize(AlgorithmParameterSpec param)Initializes thisKeyPairGeneratorwith the givenAlgorithmParameterSpec.voidinitialize(AlgorithmParameterSpec param, SecureRandom random)Initializes thisKeyPairGeneratorwith the givenAlgorithmParameterSpecand the givenSecureRandom.
-
-
-
Constructor Detail
-
KeyPairGenerator
protected KeyPairGenerator(String algorithm)
Constructs a new instance ofKeyPairGeneratorwith the name of the algorithm to use.- Parameters:
algorithm- the name of algorithm to use
-
-
Method Detail
-
getAlgorithm
public String getAlgorithm()
Returns the name of the algorithm of thisKeyPairGenerator.- Returns:
- the name of the algorithm of this
KeyPairGenerator
-
getInstance
public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
Returns a new instance ofKeyPairGeneratorthat utilizes the specified algorithm.- Parameters:
algorithm- the name of the algorithm to use- Returns:
- a new instance of
KeyPairGeneratorthat utilizes the specified algorithm - Throws:
NoSuchAlgorithmException- if the specified algorithm is not availableNullPointerException- ifalgorithmisnull
-
getInstance
public static KeyPairGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
Returns a new instance ofKeyPairGeneratorthat utilizes the specified algorithm from the specified provider.- Parameters:
algorithm- the name of the algorithm to useprovider- the name of the provider- Returns:
- a new instance of
KeyPairGeneratorthat utilizes the specified algorithm from the specified provider - Throws:
NoSuchAlgorithmException- if the specified algorithm is not availableNoSuchProviderException- if the specified provider is not availableNullPointerException- ifalgorithmisnullIllegalArgumentException- ifprovider == null || provider.isEmpty()
-
getInstance
public static KeyPairGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
Returns a new instance ofKeyPairGeneratorthat utilizes the specified algorithm from the specified provider. Theprovidersupplied does not have to be registered.- Parameters:
algorithm- the name of the algorithm to useprovider- the provider- Returns:
- a new instance of
KeyPairGeneratorthat utilizes the specified algorithm from the specified provider - Throws:
NoSuchAlgorithmException- if the specified algorithm is not availableNullPointerException- ifalgorithmisnullIllegalArgumentException- ifprovider == null
-
getProvider
public final Provider getProvider()
Returns the provider associated with thisKeyPairGenerator.- Returns:
- the provider associated with this
KeyPairGenerator
-
initialize
public void initialize(int keysize)
Initializes thisKeyPairGeneratorwith the given key size. The default parameter set and a defaultSecureRandominstance will be used.- Parameters:
keysize- the size of the key (number of bits)
-
initialize
public void initialize(AlgorithmParameterSpec param) throws InvalidAlgorithmParameterException
Initializes thisKeyPairGeneratorwith the givenAlgorithmParameterSpec. A defaultSecureRandominstance will be used.- Parameters:
param- the parameters to use- Throws:
InvalidAlgorithmParameterException- if the specified parameters are not supported
-
genKeyPair
public final KeyPair genKeyPair()
Computes and returns a new uniqueKeyPaireach time this method is called.This does exactly the same as
generateKeyPair().- Returns:
- a new unique
KeyPaireach time this method is called
-
generateKeyPair
public KeyPair generateKeyPair()
Computes and returns a new uniqueKeyPaireach time this method is called.This does exactly the same as
genKeyPair().- Specified by:
generateKeyPairin classKeyPairGeneratorSpi- Returns:
- a new unique
KeyPaireach time this method is called
-
initialize
public void initialize(int keysize, SecureRandom random)Initializes thisKeyPairGeneratorwith the given key size and the givenSecureRandom. The default parameter set will be used.- Specified by:
initializein classKeyPairGeneratorSpi- Parameters:
keysize- the key sizerandom- the source of randomness
-
initialize
public void initialize(AlgorithmParameterSpec param, SecureRandom random) throws InvalidAlgorithmParameterException
Initializes thisKeyPairGeneratorwith the givenAlgorithmParameterSpecand the givenSecureRandom.- Overrides:
initializein classKeyPairGeneratorSpi- Parameters:
param- the parameters to userandom- the source of randomness- Throws:
InvalidAlgorithmParameterException- if the specified parameters are not supported
-
-