Name

Class javax.crypto.KeyGenerator

Description

A KeyGenerator creates random keys for use with symmetric ciphers. To obtain a KeyGenerator, call getInstance() with an algorithm name. Then initialize the KeyGenerator by calling one of the init() methods. To create a new random key, call generateKey(). The following example shows how to create a random key for a DES cipher:

KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(new SecureRandom());
SecretKey key = kg.generateKey();

Class Definition

public class javax.crypto.KeyGenerator
  extends java.lang.Object {

  // Constructors
  protected KeyGenerator(KeyGeneratorSpi, Provider, String);

  // Class Methods
  public static final KeyGenerator getInstance(String);
  public static final KeyGenerator getInstance(String, String);

  // Instance Methods
  public final SecretKey generateKey();
  public final String getAlgorithm();
  public final Provider getProvider();
  public final void init(int);
  public final void init(int, SecureRandom);
  public final void init(SecureRandom);
  public final void init(AlgorithmParameterSpec);
  public final void init(AlgorithmParameterSpec, SecureRandom);
}

See Also

AlgorithmParameterSpec, KeyGeneratorSpi, Provider, SecretKey, Secure-Random

Get Java Cryptography now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.