APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.crypto.provider

public final Class DHKeyAgreement

extends KeyAgreementSpi
Class Inheritance
Imports
java.math.BigInteger, java.security.*, java.security.spec.AlgorithmParameterSpec, java.util.Arrays, javax.crypto.KeyAgreementSpi, .SecretKey, .ShortBufferException, javax.crypto.spec.DHParameterSpec, .SecretKeySpec, sun.security.util.KeyUtil

This class implements the Diffie-Hellman key agreement protocol between any number of parties.
Author
Jan Luehe

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private BigInteger
private BigInteger
private BigInteger
x

private BigInteger
y

Constructor Summary

AccessConstructor and Description
public
DHKeyAgreement()

Empty constructor

Method Summary

Modifier and TypeMethod and Description
protected Key

Returns:

the (intermediate) key resulting from this phase, or null if this phase does not yield a key
engineDoPhase
(Key
the key for this phase. For example, in the case of Diffie-Hellman between 2 parties, this would be the other party's Diffie-Hellman public key.
key
,
boolean
flag which indicates if this is the last phase of this key agreement.
lastPhase
)

Implements abstract javax.crypto.KeyAgreementSpi.engineDoPhase.

Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.

protected byte[]

Returns:

the new buffer with the shared secret
engineGenerateSecret
()

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret and returns it in a new buffer.

protected int

Returns:

the number of bytes placed into sharedSecret
engineGenerateSecret
(byte[]
the buffer for the shared secret
sharedSecret
,
int
the offset in sharedSecret where the shared secret will be stored
offset
)

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset.

protected SecretKey

Returns:

the shared secret key
engineGenerateSecret
(String
the requested secret key algorithm
algorithm
)

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Creates the shared secret and returns it as a secret key object of the requested algorithm type.

protected void
engineInit(Key
the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.
key
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key and source of randomness.

protected void
engineInit(Key
the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.
key
,
AlgorithmParameterSpec
the key agreement parameters
params
,
SecureRandom
the source of randomness
random
)

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness.

Field Detail

generateSecretback to summary
private boolean generateSecret
init_gback to summary
private BigInteger init_g
init_pback to summary
private BigInteger init_p
xback to summary
private BigInteger x
yback to summary
private BigInteger y

Constructor Detail

DHKeyAgreementback to summary
public DHKeyAgreement()

Empty constructor

Method Detail

engineDoPhaseback to summary
protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException

Implements abstract javax.crypto.KeyAgreementSpi.engineDoPhase.

Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.

Parameters
key:Key

the key for this phase. For example, in the case of Diffie-Hellman between 2 parties, this would be the other party's Diffie-Hellman public key.

lastPhase:boolean

flag which indicates if this is the last phase of this key agreement.

Returns:Key

the (intermediate) key resulting from this phase, or null if this phase does not yield a key

Exceptions
InvalidKeyException:
if the given key is inappropriate for this phase.
IllegalStateException:
if this key agreement has not been initialized.
engineGenerateSecretback to summary
protected byte[] engineGenerateSecret() throws IllegalStateException

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret and returns it in a new buffer.

This method resets this KeyAgreementSpi object, so that it can be reused for further key agreements. Unless this key agreement is reinitialized with one of the engineInit methods, the same private information and algorithm parameters will be used for subsequent key agreements.

Returns:byte[]

the new buffer with the shared secret

Exceptions
IllegalStateException:
if this key agreement has not been completed yet
engineGenerateSecretback to summary
protected int engineGenerateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset.

If the sharedSecret buffer is too small to hold the result, a ShortBufferException is thrown. In this case, this call should be repeated with a larger output buffer.

This method resets this KeyAgreementSpi object, so that it can be reused for further key agreements. Unless this key agreement is reinitialized with one of the engineInit methods, the same private information and algorithm parameters will be used for subsequent key agreements.

Parameters
sharedSecret:byte[]

the buffer for the shared secret

offset:int

the offset in sharedSecret where the shared secret will be stored

Returns:int

the number of bytes placed into sharedSecret

Exceptions
IllegalStateException:
if this key agreement has not been completed yet
ShortBufferException:
if the given output buffer is too small to hold the secret
engineGenerateSecretback to summary
protected SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException

Implements abstract javax.crypto.KeyAgreementSpi.engineGenerateSecret.

Creates the shared secret and returns it as a secret key object of the requested algorithm type.

This method resets this KeyAgreementSpi object, so that it can be reused for further key agreements. Unless this key agreement is reinitialized with one of the engineInit methods, the same private information and algorithm parameters will be used for subsequent key agreements.

Parameters
algorithm:String

the requested secret key algorithm

Returns:SecretKey

the shared secret key

Exceptions
IllegalStateException:
if this key agreement has not been completed yet
NoSuchAlgorithmException:
if the requested secret key algorithm is not available
InvalidKeyException:
if the shared secret key material cannot be used to generate a secret key of the requested algorithm type (e.g., the key material is too short)
engineInitback to summary
protected void engineInit(Key key, SecureRandom random) throws InvalidKeyException

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key and source of randomness. The given key is required to contain all the algorithm parameters required for this key agreement.

If the key agreement algorithm requires random bytes, it gets them from the given source of randomness, random. However, if the underlying algorithm implementation does not require any random bytes, random is ignored.

Parameters
key:Key

the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for this key agreement, e.g., is of the wrong type or has an incompatible algorithm type.
engineInitback to summary
protected void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.KeyAgreementSpi.engineInit.

Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness.

Parameters
key:Key

the party's private information. For example, in the case of the Diffie-Hellman key agreement, this would be the party's own Diffie-Hellman private key.

params:AlgorithmParameterSpec

the key agreement parameters

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for this key agreement, e.g., is of the wrong type or has an incompatible algorithm type.
InvalidAlgorithmParameterException:
if the given parameters are inappropriate for this key agreement.
com.sun.crypto.provider back to summary

private Class DHKeyAgreement.AllowKDF

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

VALUEback to summary
private static final boolean VALUE

Constructor Detail

AllowKDFback to summary
private AllowKDF()