Overview | Package | Class | Tree | Deprecated | Index | Help
| Oracle Security Developer Tools Crypto Java API Reference 10g Release 3 (10.1.3) B25378-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## oracle.security.crypto.core
Class DiffieHellman

`java.lang.Object
oracle.security.crypto.core.DiffieHellman`

public class DiffieHellman
extends java.lang.Object

This class encapsulates the Diffie-Hellman public key agreement algorithm.

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.

Field Summary
`protected java.math.BigInteger` | `g` The generator.
`protected java.math.BigInteger` | `gx` The generated value g^x.
`protected java.math.BigInteger` | `p` The prime.
`protected java.math.BigInteger` | `x` The large random integer.

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
`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()`
`static DiffieHellman` | `getInstance(java.math.BigInteger p, java.math.BigInteger g, RandomBitsSource rbs)`
`static DiffieHellman` | `getInstance(RandomBitsSource rbs, int len)`
`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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### p

    protected java.math.BigInteger p

  The prime.

### g

    protected java.math.BigInteger g

  The generator.

### x

    protected java.math.BigInteger x

  The large random integer.

### gx

    protected java.math.BigInteger gx

  The generated value g^x.

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.

### 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

  Throws:
    `AlgorithmIdentifierException`

### getInstance

    public static DiffieHellman getInstance(RandomBitsSource rbs,
                                            int len)
                                     throws java.lang.IllegalArgumentException,
                                            AlgorithmIdentifierException

  Throws:
    `java.lang.IllegalArgumentException`
    `AlgorithmIdentifierException`

### getInstance

    public static DiffieHellman getInstance(java.math.BigInteger p,
                                            java.math.BigInteger g,
                                            RandomBitsSource rbs)
                                     throws AlgorithmIdentifierException

  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.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Oracle Security Developer Tools Crypto Java API Reference 10g Release 3 (10.1.3) B25378-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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