public class RSAKeyPairGenerator
extends java.security.KeyPairGenerator
For creating a RSA key pair, a KeyPairGenerator has to be instantiated,
properly initialized and directed to actually generate the keys by calling
the generateKeyPair
method. If the generator is
not initialized by explicitly calling an initialize
method, the
modulus length per default is set to 2048 bits.
Generating RSA keys using a modulus length of, e.g. 1024 bits, may be done by:
KeyPairGenerator key_gen = KeyPairGenerator.getIntance("RSA"); key_gen.initialize(1024, sec_random); KeyPair key_pair = key_gen.generateKeyPair();
KeyPairGenerator
,
KeyPair
,
RSAPublicKey
,
RSAPrivateKey
,
RSAKeyFactory
Modifier and Type | Field and Description |
---|---|
protected boolean |
initialized |
protected int |
keylen |
protected java.math.BigInteger |
public_exponent |
protected java.security.SecureRandom |
random |
Constructor and Description |
---|
RSAKeyPairGenerator()
Default constructor for creating a RSAKeyPairGenerator object.
|
Modifier and Type | Method and Description |
---|---|
java.security.KeyPair |
generateKeyPair()
Actually generates the requested RSA KeyPair.
|
void |
initialize(java.security.spec.AlgorithmParameterSpec params)
Initializes this RSAKeyPairGenerator with the given AlgorithmParameterSpec.
|
void |
initialize(java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this RSAPssKeyPairGenerator with given AlgorithmParameterSpec and
random number generator.
|
void |
initialize(int strength)
Initializes the RSAKeyPairGenerator for a certain key length with the
default random seed.
|
void |
initialize(int strength,
java.math.BigInteger publicExponent,
java.security.SecureRandom secureRandom)
Initializes the key pair generator using the specified "strength" (desired
key length in bits), public exponent, and source of random bits.
|
void |
initialize(int strength,
java.security.SecureRandom secureRandom)
Initializes the RSAKeyPairGenerator for a certain key length with the given
random seed.
|
protected int keylen
protected java.security.SecureRandom random
protected java.math.BigInteger public_exponent
protected boolean initialized
public RSAKeyPairGenerator()
public void initialize(int strength)
initialize
in class java.security.KeyPairGenerator
strength
- the length of the key in bits.public void initialize(int strength, java.security.SecureRandom secureRandom)
initialize
in class java.security.KeyPairGenerator
strength
- the length of the key in bits.secureRandom
- the random seedpublic void initialize(int strength, java.math.BigInteger publicExponent, java.security.SecureRandom secureRandom)
When using this initialization method an explicit cast to RSAKeyPairGenerator has to be made:
RSAKeyPairGenerator keyGen = (RSAKeyPairGenerator)KeyPairGenerator.getInstance("RSA", "IAIK"); keyGen.initialize(strength, publicExponent, secureRandom); ...
strength
- keyLength the length of the key in bits.publicExponent
- the public exponentsecureRandom
- the random seedpublic void initialize(java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException
initialize
in class java.security.KeyPairGenerator
params
- the RSAPssParameterSpec for initializing this generatorjava.security.InvalidAlgorithmParameterException
- if the given parameter specification is not a
RSAKeyGenParameterSpecpublic void initialize(java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidAlgorithmParameterException
initialize
in class java.security.KeyPairGenerator
params
- the RSAKeyGenParameterSpec for initializing this generatorrandom
- the SecureRandom for generating random numbersjava.security.InvalidAlgorithmParameterException
- if the given parameter specification is not a
RSAKeyGenParameterSpecpublic java.security.KeyPair generateKeyPair()
generateKeyPair
in class java.security.KeyPairGenerator