de.flexiprovider.core.elgamal
Class ElGamalKeyPairGenerator

java.lang.Object
  |
  +--java.security.KeyPairGeneratorSpi
        |
        +--de.flexiprovider.api.keys.KeyPairGenerator
              |
              +--de.flexiprovider.core.elgamal.ElGamalKeyPairGenerator

public class ElGamalKeyPairGenerator
extends KeyPairGenerator

This class is used to generate key pairs for the ElGamal encryption algorithm (implemented by ElGamal). It can be initialized with the bit length of the prime p. The default bit length of the prime p is 1024 bits.

Author:
Thomas Wahrenbruch, Martin Döring

Field Summary
static java.lang.String OID
          The OID of ElGamal.
 
Constructor Summary
ElGamalKeyPairGenerator()
           
 
Method Summary
 KeyPair genKeyPair()
          Generate a key pair, containing an ElGamalPublicKey and an ElGamalPrivateKey.
 void initialize(AlgorithmParameterSpec params, SecureRandom random)
          Initialize the key pair generator with the specified parameters and source of randomness.
 void initialize(int keySize, SecureRandom random)
          Initialize the key pair generator with the specified key size and source of randomness.
 
Methods inherited from class de.flexiprovider.api.keys.KeyPairGenerator
generateKeyPair, initialize, initialize
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OID

public static final java.lang.String OID
The OID of ElGamal.
Constructor Detail

ElGamalKeyPairGenerator

public ElGamalKeyPairGenerator()
Method Detail

initialize

public void initialize(AlgorithmParameterSpec params,
                       SecureRandom random)
                throws InvalidAlgorithmParameterException
Initialize the key pair generator with the specified parameters and source of randomness. If the parameters are null, the default parameters are used.
Overrides:
initialize in class KeyPairGenerator
Parameters:
params - the parameters
random - the source of randomness
Throws:
InvalidAlgorithmParameterException - if the parameters are not an instance of ElGamalKeyGenParameterSpec.

initialize

public void initialize(int keySize,
                       SecureRandom random)
Initialize the key pair generator with the specified key size and source of randomness.
Overrides:
initialize in class KeyPairGenerator
Parameters:
keySize - the bit length of the prime p
random - the source of randomness

genKeyPair

public KeyPair genKeyPair()
Generate a key pair, containing an ElGamalPublicKey and an ElGamalPrivateKey.

The prime p is always of the form 2*q+1. The algorithm generates a prime number q and computes p = 2*q+1 until p is prime. Then, a generator of the group (Z/pZ)* is generated. In the last step, a random number a with 0 < a < p-2, is chosen. The public key parameters are A = ga mod p, p, and g. The private key parameters are a, p, and g.

Overrides:
genKeyPair in class KeyPairGenerator
Returns:
the generated key pair