javax.crypto
Class KeyAgreementSpi

java.lang.Object
  extended by javax.crypto.KeyAgreementSpi

public abstract class KeyAgreementSpi
extends Object

This is the Service Provider Interface (SPI) for the KeyAgreement class.

Providers wishing to implement a key agreement algorithm must subclass this and provide an appropriate implementation for all the abstract methods below, and provide an appropriate entry in the master Provider class (the service name for key agreement algorithms is "KeyAgreement").

Since:
1.4
See Also:
KeyAgreement, SecretKey

Constructor Summary
KeyAgreementSpi()
          Create a new KeyAgreementSpi instance.
 
Method Summary
protected abstract  Key engineDoPhase(Key key, boolean lastPhase)
          Do a phase in the key agreement.
protected abstract  byte[] engineGenerateSecret()
          Generate the shared secret in a new byte array.
protected abstract  int engineGenerateSecret(byte[] sharedSecret, int offset)
          Generate the shared secret, storing it into the specified array.
protected abstract  SecretKey engineGenerateSecret(String algorithm)
          Generate the shared secret and return it as a SecretKey.
protected abstract  void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random)
          Initialize this key agreement with a key, parameters, and source of randomness.
protected abstract  void engineInit(Key key, SecureRandom random)
          Initialize this key agreement with a key and source of randomness.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyAgreementSpi

public KeyAgreementSpi()
Create a new KeyAgreementSpi instance.

Method Detail

engineDoPhase

protected abstract Key engineDoPhase(Key key,
                                     boolean lastPhase)
                              throws IllegalStateException,
                                     InvalidKeyException
Do a phase in the key agreement.

Parameters:
key - The key to use for this phase.
lastPhase - true if this call should be the last phase.
Returns:
The intermediate result, or null if there is no intermediate result.
Throws:
IllegalStateException - If this instance has not been initialized.
InvalidKeyException - If the supplied key is not appropriate.

engineGenerateSecret

protected abstract byte[] engineGenerateSecret()
                                        throws IllegalStateException
Generate the shared secret in a new byte array.

Returns:
The shared secret in a new byte array.
Throws:
IllegalStateException - If this key agreement is not ready to generate the secret.

engineGenerateSecret

protected abstract int engineGenerateSecret(byte[] sharedSecret,
                                            int offset)
                                     throws IllegalStateException,
                                            ShortBufferException
Generate the shared secret, storing it into the specified array.

Parameters:
sharedSecret - The byte array in which to store the secret.
offset - The offset into the byte array to start.
Returns:
The size of the shared secret.
Throws:
IllegalStateException - If this key agreement is not ready to generate the secret.
ShortBufferException - If there is not enough space in the supplied array for the shared secret.

engineGenerateSecret

protected abstract SecretKey engineGenerateSecret(String algorithm)
                                           throws IllegalStateException,
                                                  InvalidKeyException,
                                                  NoSuchAlgorithmException
Generate the shared secret and return it as a SecretKey.

Parameters:
algorithm - The algorithm with which to generate the secret key.
Returns:
The shared secret as a secret key.
Throws:
IllegalStateException - If this key agreement is not ready to generate the secret.
InvalidKeyException - If the shared secret cannot be made into a SecretKey.
NoSuchAlgorithmException - If algorithm cannot be found.

engineInit

protected abstract void engineInit(Key key,
                                   AlgorithmParameterSpec params,
                                   SecureRandom random)
                            throws InvalidAlgorithmParameterException,
                                   InvalidKeyException
Initialize this key agreement with a key, parameters, and source of randomness.

Parameters:
key - The key to initialize with, usually a private key.
params - The parameters to initialize with.
random - The source of randomness to use.
Throws:
InvalidAlgorithmParameterException - If the supplied parameters are inappropriate.
InvalidKeyException - If the supplied key is inappropriate.

engineInit

protected abstract void engineInit(Key key,
                                   SecureRandom random)
                            throws InvalidKeyException
Initialize this key agreement with a key and source of randomness.

Parameters:
key - The key to initialize with, usually a private key.
random - The source of randomness to use.
Throws:
InvalidKeyException - If the supplied key is inappropriate.