KeyGenerator (Java SE 15 & JDK 15) (original) (raw)


public class KeyGenerator extends Object

This class provides the functionality of a secret (symmetric) key generator.

Key generators are constructed using one of the getInstance class methods of this class.

KeyGenerator objects are reusable, i.e., after a key has been generated, the same KeyGenerator object can be re-used to generate further keys.

There are two ways to generate a key: in an algorithm-independent manner, and in an algorithm-specific manner. The only difference between the two is the initialization of the object:

In case the client does not explicitly initialize the KeyGenerator (via a call to an init method), each provider must supply (and document) a default initialization. See the Keysize Restriction sections of theJDK Providers document for information on the KeyGenerator defaults used by JDK providers. However, note that defaults may vary across different providers. Additionally, the default value for a provider may change in a future version. Therefore, it is recommended to explicitly initialize the KeyGenerator instead of relying on provider-specific defaults.

Every implementation of the Java platform is required to support the following standard KeyGenerator algorithms with the keysizes in parentheses:

These algorithms are described in the KeyGenerator section of the Java Security Standard Algorithm Names Specification. Consult the release documentation for your implementation to see if any other algorithms are supported.

Since:

1.4

See Also:

SecretKey

Constructors

Modifier Constructor Description
protected KeyGenerator​(KeyGeneratorSpi keyGenSpi,Provider provider,String algorithm) Creates a KeyGenerator object.
Modifier and Type Method Description
SecretKey generateKey() Generates a secret key.
String getAlgorithm() Returns the algorithm name of this KeyGenerator object.
static KeyGenerator getInstance​(String algorithm) Returns a KeyGenerator object that generates secret keys for the specified algorithm.
static KeyGenerator getInstance​(String algorithm,String provider) Returns a KeyGenerator object that generates secret keys for the specified algorithm.
static KeyGenerator getInstance​(String algorithm,Provider provider) Returns a KeyGenerator object that generates secret keys for the specified algorithm.
Provider getProvider() Returns the provider of this KeyGenerator object.
void init​(int keysize) Initializes this key generator for a certain keysize.
void init​(int keysize,SecureRandom random) Initializes this key generator for a certain keysize, using a user-provided source of randomness.
void init​(SecureRandom random) Initializes this key generator.
void init​(AlgorithmParameterSpec params) Initializes this key generator with the specified parameter set.
void init​(AlgorithmParameterSpec params,SecureRandom random) Initializes this key generator with the specified parameter set and a user-provided source of randomness.

Methods declared in class java.lang.Object

[clone](../../java/lang/Object.html#clone%28%29), [equals](../../java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../java/lang/Object.html#finalize%28%29), [getClass](../../java/lang/Object.html#getClass%28%29), [hashCode](../../java/lang/Object.html#hashCode%28%29), [notify](../../java/lang/Object.html#notify%28%29), [notifyAll](../../java/lang/Object.html#notifyAll%28%29), [toString](../../java/lang/Object.html#toString%28%29), [wait](../../java/lang/Object.html#wait%28%29), [wait](../../java/lang/Object.html#wait%28long%29), [wait](../../java/lang/Object.html#wait%28long,int%29)