All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class javax.crypto.KeyAgreement

java.lang.Object
    |
    +----javax.crypto.KeyAgreement

public class KeyAgreement
extends Object
This class provides the functionality of a key agreement protocol. The keys involved in establishing a shared secret are created by one of the key generators (KeyPairGenerator or KeyGenerator), a KeyFactory, or as a result from an intermediate phase of the key agreement protocol (see doPhase).

See Also:
java.security.AlgorithmParameterGenerator, java.security.AlgorithmParameters, java.security.KeyPairGenerator, java.security.KeyFactory, KeyGenerator, java.security.spec.KeySpec, java.security.spec.AlgorithmParameterSpec, DHPrivateKeySpec, DHPublicKeySpec, DHParameterSpec, DHGenParameterSpec

Constructor Index

 o KeyAgreement(KeyAgreementSpi, Provider, String)
Creates a KeyAgreement object.

Method Index

 o doPhase(int, Key)
Executes the next phase phase of the key agreement protocol, using the provided key key.
 o generateSecret()
Generates the shared secret and returns it in a new buffer.
 o generateSecret(byte[], int)
Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset.
 o getAlgorithm()
Returns the standard name of the key agreement algorithm.
 o getInstance(String)
Generates a KeyAgreement object for the specified key agreement algorithm.
 o getInstance(String, String)
Generates a KeyAgreement object for the specified key agreement algorithm from the specified provider.
 o getProvider()
Returns the provider of this KeyAgreement object.
 o init(AlgorithmParameterSpec)
Initializes this key agreement with a set of parameters.
 o init(AlgorithmParameterSpec, SecureRandom)
Initializes this key agreement with a set of parameters and a source of randomness.
 o init(SecureRandom)
Initializes this key agreement to get random bytes (if needed) from random.

Constructors

 o KeyAgreement
protected KeyAgreement(KeyAgreementSpi keyAgreeSpi,
                       Provider provider,
                       String algorithm)
Creates a KeyAgreement object.

Parameters:
keyAgreeSpi - the delegate
provider - the provider
algorithm - the algorithm

Methods

 o getAlgorithm
public final String getAlgorithm()
Returns the standard name of the key agreement algorithm. See Appendix A in the Java Cryptography Extension API Specification & Reference for information about standard algorithm names.

Returns:
the standard algorithm name.
 o getInstance
public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException
Generates a KeyAgreement object for the specified key agreement algorithm.

Parameters:
algorithm - the standard name of the requested key agreement algorithm. See Appendix A in the Java Cryptography Extension API Specification & Reference for information about standard algorithm names.
Returns:
the new KeyAgreement object
Throws: NoSuchAlgorithmException
if the requested key agreement algorithm is not available
 o getInstance
public static final KeyAgreement getInstance(String algorithm,
                                             String provider) throws NoSuchAlgorithmException, NoSuchProviderException
Generates a KeyAgreement object for the specified key agreement algorithm from the specified provider.

Parameters:
algorithm - the standard name of the requested key agreement algorithm. See Appendix A in the Java Cryptography Extension API Specification & Reference for information about standard algorithm names.
provider - the name of the provider
Returns:
the new KeyAgreement object
Throws: NoSuchAlgorithmException
if the requested key agreement algorithm is not available from the provider
Throws: NoSuchProviderException
if the requested provider is not available
See Also:
java.security.Provider
 o getProvider
public final Provider getProvider()
Returns the provider of this KeyAgreement object.

Returns:
the provider of this KeyAgreement object
 o init
public final void init(SecureRandom random)
Initializes this key agreement to get random bytes (if needed) from random. If the underlying implementation does not require any random bytes, random is ignored.

Parameters:
random - the source of randomness
 o init
public final void init(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException
Initializes this key agreement with a set of parameters.

Parameters:
params - the key agreement parameters
Throws: InvalidAlgorithmParameterException
if the given parameters are inappropriate for this key agreement protocol
 o init
public final void init(AlgorithmParameterSpec params,
                       SecureRandom random) throws InvalidAlgorithmParameterException
Initializes this key agreement with a set of parameters and a source of randomness.

Parameters:
params - the key agreement parameters
random - the source of randomness
Throws: InvalidAlgorithmParameterException
if the given parameters are inappropriate for this key agreement protocol
 o doPhase
public final Key doPhase(int phase,
                         Key key) throws IllegalStateException, InvalidKeyException
Executes the next phase phase of the key agreement protocol, using the provided key key.

Parameters:
phase - the phase of the key agreement protocol to be executed
key - the key for this phase
Returns:
the key resulting from phase, or null if phase does not yield a key
Throws: IllegalStateException
if phase is inappropriate for this key agreement protocol, or does not correspond to the next phase in the protocol sequence
Throws: InvalidKeyException
if the given key is inappropriate for this key agreement protocol, or inappropriate for the specified phase phase
 o generateSecret
public final byte[] generateSecret() throws IllegalStateException
Generates the shared secret and returns it in a new buffer.

The key agreement is reset to its initial state after this call.

Returns:
the new buffer with the shared secret
Throws: IllegalStateException
if this key agreement has not been completed yet
 o generateSecret
public final int generateSecret(byte[] sharedSecret,
                                int offset) throws IllegalStateException, ShortBufferException
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.

After this call has completed successfully, this KeyAgreement is reset to its initial state (uninitialized), and can be re-used for further key agreements.

Parameters:
sharedSecret - the buffer for the shared secret
offset - the offset in sharedSecret where the shared secret will be stored
Returns:
the number of bytes placed into sharedSecret
Throws: IllegalStateException
if this key agreement has not been completed yet
Throws: ShortBufferException
if the given output buffer is too small to hold the secret

All Packages  Class Hierarchy  This Package  Previous  Next  Index