iaik.security.rsa
Class RSAKeyPairGenerator

java.lang.Object
  |
  +--java.security.KeyPairGeneratorSpi
        |
        +--java.security.KeyPairGenerator
              |
              +--iaik.security.rsa.RSAKeyPairGenerator

public class RSAKeyPairGenerator
extends KeyPairGenerator

The RSAKeyPairGenerator class is used to generate keys for the RSA algorithm.

The modulus of the generated KeyPair always has 1024+256x bits. The value x is internally created from the key length. If no initialize() method of this key pair generator is called, it defaults to initialize(1024).

The algorithm used for key generation was published in RSA LABORATORIES' CryptoBytes, Volume 3, Number 1 - Spring 1997, page 9

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. 512 bits, may be done by:

 KeyPairGenerator key_gen = KeyPairGenerator.getIntance("RSA");
 key_gen.initialize(512, sec_random);
 KeyPair key_pair = key_gen.generateKeyPair();
 

The example above initializes the key pair generator algorithm-independent by only specifying the length of the modulus. For performing an algorithm-specific initialization, an explicit cast to RSAKeyPairGenerator would be necessary:

 RSAKeyPairGenerator dsa_key_gen = (RSAKeyPairGenerator)key_gen;
 rsa_key_gen.initialize(512, pub_exponent, sec_random);
 

Guidelines on how to create some key using a KeyPairGenerator can be found in http://java.sun.com/products/JDK/1.2/docs/guide/security/CryptoSpec.html.

Version:
File Revision 20
See Also:
KeyPairGenerator, KeyPair, RSACipher, RSAKey, RSAPublicKey, RSAPrivateKey, RSAKeyFactory

Constructor Summary
RSAKeyPairGenerator()
          Default constructor for creating a RSAKeyPairGenerator object.
 
Method Summary
 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, BigInteger publicExponent, 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, SecureRandom secureRandom)
          Initializes the RSAKeyPairGenerator for a certain key length with the given random seed.
 
Methods inherited from class java.security.KeyPairGenerator
genKeyPair, getAlgorithm, getInstance, getInstance, getProvider, initialize, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RSAKeyPairGenerator

public RSAKeyPairGenerator()
Default constructor for creating a RSAKeyPairGenerator object.
Method Detail

initialize

public void initialize(int strength)
Initializes the RSAKeyPairGenerator for a certain key length with the default random seed.
Overrides:
initialize in class KeyPairGenerator
Parameters:
strength - the length of the key in bits.

initialize

public void initialize(int strength,
                       SecureRandom secureRandom)
Initializes the RSAKeyPairGenerator for a certain key length with the given random seed.
Overrides:
initialize in class KeyPairGenerator
Parameters:
strength - the length of the key in bits.
secureRandom - the random seed.

initialize

public void initialize(int strength,
                       BigInteger publicExponent,
                       SecureRandom secureRandom)
                throws InvalidParameterException
Initializes the key pair generator using the specified "strength" (desired key length in bits), public exponent, and source of random bits. Typical values for the public exponent are the Fermat primes F4 and F0 (0x10001 and 0x11) and, less commonly, 17.
Parameters:
strength - keyLength the length of the key in bits.
publicExponent - the public exponent
secureRandom - the random seed

generateKeyPair

public KeyPair generateKeyPair()
Actually generates the requested RSA KeyPair.
Overrides:
generateKeyPair in class KeyPairGenerator
Returns:
the requested KeyPair

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK