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 1024 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(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)
strength
- keyLength the length of the key in bits.publicExponent
- the public exponentsecureRandom
- the random seed (must be either an instance of
SHA256FIPS186Random, SHA284FIPS186Random or SHA512FIPS186Random).public java.security.KeyPair generateKeyPair()
generateKeyPair
in class java.security.KeyPairGenerator