All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.security.KeyPairGenerator

java.lang.Object
   |
   +----java.security.KeyPairGenerator

public abstract class KeyPairGenerator
extends Object
The KeyPairGenerator class is used to generate pairs of public and private keys. Key generators are constructed using the getInstance factory methods (static methods that return instances of a given class).

Key generation is an area that sometimes does not lend itself well to algorithm independence. For example, it is possible to generate a DSA key pair specifying key family parameters (p, q and g), while it is not possible to do so for an RSA key pair. That is, those parameters are applicable to DSA but not to RSA.

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

All key pair generators share the concepts of a "strength" and a source of randomness. The measure of strength is universally shared by all algorithms, though it is interpreted differently for different algorithms. The initialize method in this KeyPairGenerator class takes these two universally shared types of arguments.

Since no other parameters are specified when you call this algorithm-independent initialize method, all other values, such as algorithm parameters, public exponent, etc., are defaulted to standard values.

It is sometimes desirable to initialize a key pair generator object using algorithm-specific semantics. For example, you may want to initialize a DSA key generator for a given set of parameters p, q and g, or an RSA key generator for a given public exponent.

This is done through algorithm-specific standard interfaces. Rather than calling the algorithm-independent KeyPairGenerator initialize method, the key pair generator is cast to an algorithm-specific interface so that one of its specialized parameter initialization methods can be called. An example is the DSAKeyPairGenerator interface (from java.security.interfaces).

See The KeyPairGenerator Class in the "Java Cryptography Architecture API Specification & Reference" for more information and examples.

See Also:
DSAKeyPairGenerator

Constructor Index

 o KeyPairGenerator(String)
Creates a KeyPairGenerator object for the specified algorithm.

Method Index

 o generateKeyPair()
Generates a key pair.
 o getAlgorithm()
Returns the standard name of the algorithm for this key generator.
 o getInstance(String)
Generates a KeyPairGenerator object that implements the algorithm requested, as available in the environment.
 o getInstance(String, String)
Generates a KeyPairGenerator object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.
 o initialize(int)
Initializes the key pair generator for a certain strength using a system-provided source of randomness.
 o initialize(int, SecureRandom)
Initializes the key pair generator for a certain strength.

Constructors

 o KeyPairGenerator
 protected KeyPairGenerator(String algorithm)
Creates a KeyPairGenerator object for the specified algorithm.

Parameters:
algorithm - the standard string name of the algorithm. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.

Methods

 o getAlgorithm
 public String getAlgorithm()
Returns the standard name of the algorithm for this key generator. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.

Returns:
the standard string name of the algorithm.
 o getInstance
 public static KeyPairGenerator getInstance(String algorithm) throws NoSuchAlgorithmException
Generates a KeyPairGenerator object that implements the algorithm requested, as available in the environment.

Parameters:
algorithm - the standard string name of the algorithm. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
Returns:
the new KeyPairGenerator object.
Throws: NoSuchAlgorithmException
if the algorithm is not available in the environment.
 o getInstance
 public static KeyPairGenerator getInstance(String algorithm,
                                            String provider) throws NoSuchAlgorithmException, NoSuchProviderException
Generates a KeyPairGenerator object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.

Parameters:
algorithm - the standard string name of the algorithm. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
provider - the string name of the provider.
Returns:
the new KeyPairGenerator object.
Throws: NoSuchAlgorithmException
if the algorithm is not available from the provider.
Throws: NoSuchProviderException
if the provider is not available in the environment.
See Also:
Provider
 o initialize
 public abstract void initialize(int strength,
                                 SecureRandom random)
Initializes the key pair generator for a certain strength.

Parameters:
strength - the strength of the key. This is an algorithm-specific metric, such as modulus length.
random - the source of randomness for this generator.
 o initialize
 public void initialize(int strength)
Initializes the key pair generator for a certain strength using a system-provided source of randomness.

Parameters:
strength - the strength of the key. This is an algorithm-specific metric, such as modulus length.
 o generateKeyPair
 public abstract KeyPair generateKeyPair()
Generates a key pair. Unless an initialization method is called using a KeyPairGenerator interface, algorithm-specific defaults will be used. This will generate a new key pair every time it is called.


All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature