javax.crypto

Class KeyAgreementSpi

public abstract class KeyAgreementSpi extends Object

This is the Service Provider Interface (SPI) for the {@link javax.crypto.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 {@link java.security.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 KeyengineDoPhase(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 intengineGenerateSecret(byte[] sharedSecret, int offset)
Generate the shared secret, storing it into the specified array.
protected abstract SecretKeyengineGenerateSecret(String algorithm)
Generate the shared secret and return it as a {@link SecretKey}.
protected abstract voidengineInit(Key key, AlgorithmParameterSpec params, SecureRandom random)
Initialize this key agreement with a key, parameters, and source of randomness.
protected abstract voidengineInit(Key key, SecureRandom random)
Initialize this key agreement with a key and source of randomness.

Constructor Detail

KeyAgreementSpi

public KeyAgreementSpi()
Create a new KeyAgreementSpi instance.

Method Detail

engineDoPhase

protected abstract Key engineDoPhase(Key key, boolean lastPhase)
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: java.lang.IllegalStateException If this instance has not been initialized. java.security.InvalidKeyException If the supplied key is not appropriate.

engineGenerateSecret

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

Returns: The shared secret in a new byte array.

Throws: java.lang.IllegalStateException If this key agreement is not ready to generate the secret.

engineGenerateSecret

protected abstract int engineGenerateSecret(byte[] sharedSecret, int offset)
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: java.lang.IllegalStateException If this key agreement is not ready to generate the secret. javax.crypto.ShortBufferException If there is not enough space in the supplied array for the shared secret.

engineGenerateSecret

protected abstract SecretKey engineGenerateSecret(String algorithm)
Generate the shared secret and return it as a {@link SecretKey}.

Parameters: algorithm The algorithm with which to generate the secret key.

Returns: The shared secret as a secret key.

Throws: java.lang.IllegalStateException If this key agreement is not ready to generate the secret. java.security.InvalidKeyException If the shared secret cannot be made into a {@link SecretKey}. java.security.NoSuchAlgorithmException If algorithm cannot be found.

engineInit

protected abstract void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random)
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: java.security.InvalidAlgorithmParameterException If the supplied parameters are inappropriate. java.security.InvalidKeyException If the supplied key is inappropriate.

engineInit

protected abstract void engineInit(Key key, SecureRandom random)
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: java.security.InvalidKeyException If the supplied key is inappropriate.