public class KeyGenerator extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
KeyGenerator(KeyGeneratorSpi keyGenSpi,
Provider provider,
String algorithm)
Creates a new
KeyGenerator instance. |
| Modifier and Type | Method and Description |
|---|---|
SecretKey |
generateKey()
Generates a secret key.
|
String |
getAlgorithm()
Returns the name of the key generation algorithm.
|
static KeyGenerator |
getInstance(String algorithm)
Creates a new
KeyGenerator instance that provides the specified
key algorithm, |
static KeyGenerator |
getInstance(String algorithm,
Provider provider)
Creates a new
KeyGenerator instance that provides the specified
key algorithm from the specified provider. |
static KeyGenerator |
getInstance(String algorithm,
String provider)
Creates a new
KeyGenerator instance that provides the specified
key algorithm from the specified provider. |
Provider |
getProvider()
Returns the provider of this
KeyGenerator instance. |
void |
init(AlgorithmParameterSpec params)
Initializes this
KeyGenerator instance with the specified
algorithm parameters. |
void |
init(AlgorithmParameterSpec params,
SecureRandom random)
Initializes this
KeyGenerator instance with the specified
algorithm parameters and randomness source. |
void |
init(int keysize)
Initializes this
KeyGenerator instance for the specified key size
(in bits). |
void |
init(int keysize,
SecureRandom random)
Initializes this
KeyGenerator instance for the specified key size
(in bits) using the specified randomness source. |
void |
init(SecureRandom random)
Initializes this
KeyGenerator with the specified randomness
source. |
protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider, String algorithm)
KeyGenerator instance.keyGenSpi - the implementation delegate.provider - the implementation provider.algorithm - the name of the algorithm.public final String getAlgorithm()
public final Provider getProvider()
KeyGenerator instance.KeyGenerator instance.public static final KeyGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
KeyGenerator instance that provides the specified
key algorithm,algorithm - the name of the requested key algorithmKeyGenerator instance.NoSuchAlgorithmException - if the specified algorithm is not available by any provider.NullPointerException - if algorithm is null.public static final KeyGenerator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
KeyGenerator instance that provides the specified
key algorithm from the specified provider.algorithm - the name of the requested key algorithm.provider - the name of the provider that is providing the algorithm.KeyGenerator instance.NoSuchAlgorithmException - if the specified algorithm is not provided by the specified
provider.NoSuchProviderException - if the specified provider is not available.IllegalArgumentException - if the specified provider is name is null or empty.NullPointerException - if the specified algorithm name is null.public static final KeyGenerator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
KeyGenerator instance that provides the specified
key algorithm from the specified provider. The provider
supplied does not have to be registered.algorithm - the name of the requested key algorithm.provider - the provider that is providing the algorithmKeyGenerator instance.NoSuchAlgorithmException - if the specified algorithm is not provided by the specified
provider.IllegalArgumentException - if the specified provider is null.NullPointerException - if the specified algorithm name is null.public final SecretKey generateKey()
public final void init(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException
KeyGenerator instance with the specified
algorithm parameters.params - the parameters for the key generation algorithm.InvalidAlgorithmParameterException - if the parameters cannot be used to initialize this key
generator algorithm.public final void init(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException
KeyGenerator instance with the specified
algorithm parameters and randomness source.params - the parameters for the key generation algorithm.random - the randomness source for any random bytes.InvalidAlgorithmParameterException - if the parameters cannot be uses to initialize this key
generator algorithm.public final void init(int keysize)
KeyGenerator instance for the specified key size
(in bits).keysize - the size of the key (in bits).public final void init(int keysize,
SecureRandom random)
KeyGenerator instance for the specified key size
(in bits) using the specified randomness source.keysize - the size of the key (in bits).random - the randomness source for any random bytes.public final void init(SecureRandom random)
KeyGenerator with the specified randomness
source.random - the randomness source for any random bytes.