public abstract class KeyPairGenerator
extends java.lang.Object
getInstance
factory methods (static methods that
return instances of a given class).
A Key pair generator for a particular algorithm creates a public/private key pair that can be used with this algorithm. It also associates algorithm-specific parameters with each of the generated keys.
There are 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 keysize.
The keysize is interpreted differently for different algorithms.
There is an
initialize
method in this KeyPairGenerator class that takes just a
keysize
argument.
For situations where a set of algorithm-specific parameters already
exists, there is
initialize
methods that have an AlgorithmParameterSpec
argument.
Every implementation of the Java platform is required to support the
following standard KeyPairGenerator
algorithms and keysizes in
parentheses:
AlgorithmParameterSpec
Modifier and Type | Method and Description |
---|---|
KeyPair |
generateKeyPair()
Generates a key pair.
|
KeyPair |
genKeyPair()
Generates a key pair.
|
java.lang.String |
getAlgorithm()
Returns the standard name of the algorithm for this key pair generator.
|
static KeyPairGenerator |
getInstance(java.lang.String algorithm)
Returns a KeyPairGenerator object that generates public/private
key pairs for the specified algorithm.
|
void |
initialize(java.security.spec.AlgorithmParameterSpec params)
Initializes the key pair generator using the specified parameter
set
That
initialize method always throws an
UnsupportedOperationException if it is not overridden |
void |
initialize(int keysize)
Initializes the key pair generator for a certain keysize using
|
public java.lang.String getAlgorithm()
public static KeyPairGenerator getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
algorithm
- the standard string name of the algorithm.
See the KeyPairGenerator section in the
Java Cryptography Architecture Standard Algorithm Name Documentation
for information about standard algorithm names.java.security.NoSuchAlgorithmException
- thrown then algorithm has wrong/unsupported algorithm namepublic void initialize(int keysize) throws InvalidParameterException
keysize
- the keysize. This is an
algorithm-specific metric, such as modulus length, specified in
number of bits.InvalidParameterException
- if the keysize
is not
supported by this KeyPairGenerator object.public void initialize(java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException
initialize
method always throws an
UnsupportedOperationException if it is not overriddenparams
- the parameter set used to generate the keys.java.security.InvalidAlgorithmParameterException
- if the given parameters
are inappropriate for this key pair generator.public final KeyPair genKeyPair()
This will generate a new key pair every time it is called.
This method is functionally equivalent to
generateKeyPair
.
public KeyPair generateKeyPair()
This will generate a new key pair every time it is called.
This method is functionally equivalent to
genKeyPair
.
Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.