Package javax.crypto
Class KeyAgreementSpi
java.lang.Object
javax.crypto.KeyAgreementSpi
- Direct Known Subclasses:
KeyAgreementSpi,KeyAgreementSpi,OpenSSLECDHKeyAgreement
public abstract class KeyAgreementSpi extends Object
The Service Provider Interface (SPI) definition for the
KeyAgreement class.-
Constructor Summary
Constructors Constructor Description KeyAgreementSpi()Creates a newKeyAgreementSpiinstance. -
Method Summary
Modifier and Type Method Description protected abstract KeyengineDoPhase(Key key, boolean lastPhase)Does the next (or the last) phase of the key agreement, using the specified key.protected abstract byte[]engineGenerateSecret()Generates the shared secret.protected abstract intengineGenerateSecret(byte[] sharedSecret, int offset)Generates the shared secret and stores it into the buffersharedSecredatoffset.protected abstract SecretKeyengineGenerateSecret(String algorithm)Generates the shared secret.protected abstract voidengineInit(Key key, SecureRandom random)Initializes thisKeyAgreementSpiwith the specified key and the specified randomness source.protected abstract voidengineInit(Key key, AlgorithmParameterSpec params, SecureRandom random)Initializes thisKeyAgreementSpiwith the specified key, algorithm parameters and randomness source.
-
Constructor Details
-
KeyAgreementSpi
public KeyAgreementSpi()Creates a newKeyAgreementSpiinstance.
-
-
Method Details
-
engineDoPhase
protected abstract Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateExceptionDoes the next (or the last) phase of the key agreement, using the specified key.- Parameters:
key- the key received from the other party for this phase.lastPhase- set totrueif this is the last phase of this key agreement.- Returns:
- the intermediate key from this phase or null if there is no intermediate key for this phase.
- Throws:
InvalidKeyException- if the specified key cannot be used in this key agreement or this phase,IllegalStateException- if this instance has not been initialized.
-
engineGenerateSecret
Generates the shared secret.- Returns:
- the generated shared secret.
- Throws:
IllegalStateException- if this key agreement is not complete.
-
engineGenerateSecret
protected abstract int engineGenerateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferExceptionGenerates the shared secret and stores it into the buffersharedSecredatoffset.- Parameters:
sharedSecret- the buffer to store the shared secret.offset- the offset in the buffer.- Returns:
- the number of bytes stored in the buffer.
- Throws:
IllegalStateException- if this key agreement is not complete.ShortBufferException- if the specified buffer is too small for the shared secret.
-
engineGenerateSecret
protected abstract SecretKey engineGenerateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyExceptionGenerates the shared secret.- Parameters:
algorithm- the algorithm to for theSecretKey- Returns:
- the shared secret as a
SecretKeyof the specified algorithm. - Throws:
IllegalStateException- if this key agreement is not complete.NoSuchAlgorithmException- if the specified algorithm for the secret key does not exists.InvalidKeyException- if aSecretKeywith the specified algorithm cannot be created using the generated shared secret.
-
engineInit
Initializes thisKeyAgreementSpiwith the specified key and the specified randomness source.- Parameters:
key- the key to initialize this key agreement.random- the source for any randomness needed.- Throws:
InvalidKeyException- if the specified key cannot be used to initialize this key agreement.
-
engineInit
protected abstract void engineInit(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterExceptionInitializes thisKeyAgreementSpiwith the specified key, algorithm parameters and randomness source.- Parameters:
key- the key to initialize this key agreement.params- the parameters for this key agreement algorithm.random- the source for any randomness needed.- Throws:
InvalidKeyException- if the specified key cannot be used to initialize this key agreement.InvalidAlgorithmParameterException- if the specified parameters are invalid for this key agreement algorithm.
-