Skip navigation links

Oracle Fusion Middleware Crypto Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10668-03


oracle.security.crypto.core
Class DiffieHellman

java.lang.Object
  extended by oracle.security.crypto.core.DiffieHellman


public final class DiffieHellman
extends java.lang.Object

Implementation of the Diffie-Hellman public key agreement algorithm, as defined in PKCS#3.

Once a DiffieHellman object has been instantiated, use the myValue() method to obtain the value to send to the peer (g^x). The method getKey(java.math.BigInteger) is used to compute the shared Diffie-Hellman key value.


Constructor Summary
DiffieHellman()
          Creates a new, uninitialized DiffieHellman instance.
DiffieHellman(java.math.BigInteger p, java.math.BigInteger g, RandomBitsSource rbs)
          Constructs a DiffieHellman object with the specified values for the prime (p) and generator (g), and creates a random value for x.
DiffieHellman(RandomBitsSource rbs, int len)
          Constructs a DiffieHellman object, creating a random prime (p) of the given bit length, and a random value x; the generator (g) is set to 4.

 

Method Summary
 void erase()
          Erases the values for this key agreement.
 void finalize()
          Finalizes this instance by erasing all sensitive data.
protected  void generatePandG(RandomBitsSource rbs, int len)
          Generates a random prime (p) of the given bit length for this DiffieHellman and sets the generator (g) to 4.
protected  void generateValues(RandomBitsSource rbs)
          Generates a large random integer (x) for this DiffieHellman, and uses its prime (p) and generator (g) to compute the value g^x.
 java.math.BigInteger getGen()
          Returns the generator (g).
static DiffieHellman getInstance()
          Returns an uninitialized DiffieHellman instance.
static DiffieHellman getInstance(java.math.BigInteger p, java.math.BigInteger g, RandomBitsSource rbs)
          Returns an initialized DiffieHellman instance.
static DiffieHellman getInstance(RandomBitsSource rbs, int len)
          Returns an initialized DiffieHellman instance.
 java.math.BigInteger getKey(java.math.BigInteger gy)
          Computes the shared DH key value g^(xy).
 java.math.BigInteger getPrime()
          Returns the prime (p).
 void initialize(java.math.BigInteger p, java.math.BigInteger g, RandomBitsSource rbs)
          Sets the prime (p) and generator (g) for this DiffieHellman, and invokes generateValues(oracle.security.crypto.core.RandomBitsSource).
 void initialize(RandomBitsSource rbs, int len)
          Generates the prime (p), generator (g) and values (x and g^x) by invoking generatePandG(oracle.security.crypto.core.RandomBitsSource, int) and generateValues(oracle.security.crypto.core.RandomBitsSource).
 java.math.BigInteger myValue()
          Returns the generated value g^x.
 java.lang.String toString()
          Returns a string representation of this object.

 

Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

DiffieHellman

public DiffieHellman()
Creates a new, uninitialized DiffieHellman instance.

DiffieHellman

public DiffieHellman(RandomBitsSource rbs,
                     int len)
              throws java.lang.IllegalArgumentException
Constructs a DiffieHellman object, creating a random prime (p) of the given bit length, and a random value x; the generator (g) is set to 4.
Throws:
java.lang.IllegalArgumentException

DiffieHellman

public DiffieHellman(java.math.BigInteger p,
                     java.math.BigInteger g,
                     RandomBitsSource rbs)
Constructs a DiffieHellman object with the specified values for the prime (p) and generator (g), and creates a random value for x.

Method Detail

getInstance

public static DiffieHellman getInstance()
                                 throws AlgorithmIdentifierException
Returns an uninitialized DiffieHellman instance.
Throws:
AlgorithmIdentifierException

getInstance

public static DiffieHellman getInstance(RandomBitsSource rbs,
                                        int len)
                                 throws java.lang.IllegalArgumentException,
                                        AlgorithmIdentifierException
Returns an initialized DiffieHellman instance.
Parameters:
rbs - The RandomBitsSource to use in this DiffieHellman object.
len - The bit length of the prime.
Throws:
java.lang.IllegalArgumentException
AlgorithmIdentifierException

getInstance

public static DiffieHellman getInstance(java.math.BigInteger p,
                                        java.math.BigInteger g,
                                        RandomBitsSource rbs)
                                 throws AlgorithmIdentifierException
Returns an initialized DiffieHellman instance.
Parameters:
p - The BigInteger prime p.
g - The BigInteger generator g.
rbs - The RandomBitsSource to use in this DiffieHellman object.
Throws:
AlgorithmIdentifierException

initialize

public void initialize(RandomBitsSource rbs,
                       int len)
Generates the prime (p), generator (g) and values (x and g^x) by invoking generatePandG(oracle.security.crypto.core.RandomBitsSource, int) and generateValues(oracle.security.crypto.core.RandomBitsSource).

initialize

public void initialize(java.math.BigInteger p,
                       java.math.BigInteger g,
                       RandomBitsSource rbs)
Sets the prime (p) and generator (g) for this DiffieHellman, and invokes generateValues(oracle.security.crypto.core.RandomBitsSource).

generatePandG

protected void generatePandG(RandomBitsSource rbs,
                             int len)
Generates a random prime (p) of the given bit length for this DiffieHellman and sets the generator (g) to 4.

generateValues

protected void generateValues(RandomBitsSource rbs)
Generates a large random integer (x) for this DiffieHellman, and uses its prime (p) and generator (g) to compute the value g^x.

getPrime

public java.math.BigInteger getPrime()
Returns the prime (p).

getGen

public java.math.BigInteger getGen()
Returns the generator (g).

myValue

public java.math.BigInteger myValue()
Returns the generated value g^x.

getKey

public java.math.BigInteger getKey(java.math.BigInteger gy)
Computes the shared DH key value g^(xy).
Parameters:
gy - The generated value received from the peer.

toString

public java.lang.String toString()
Returns a string representation of this object.
Overrides:
toString in class java.lang.Object

erase

public void erase()
Erases the values for this key agreement.

finalize

public void finalize()
Finalizes this instance by erasing all sensitive data.
Overrides:
finalize in class java.lang.Object

Skip navigation links

Oracle Fusion Middleware Crypto Java API Reference for Oracle Security Developer Tools
11g Release 1 (11.1.1)

E10668-03


Copyright © 2005, 2011 , Oracle. All rights reserved.