public class KeyAgreement extends Object
| Modifier | Constructor and Description |
|---|---|
protected |
KeyAgreement(KeyAgreementSpi keyAgreeSpi,
Provider provider,
String algorithm)
Creates a new
KeyAgreement instance. |
| Modifier and Type | Method and Description |
|---|---|
Key |
doPhase(Key key,
boolean lastPhase)
Does the next (or the last) phase of the key agreement, using the
specified key.
|
byte[] |
generateSecret()
Generates the shared secret.
|
int |
generateSecret(byte[] sharedSecret,
int offset)
Generates the shared secret and stores it into the buffer
sharedSecred at offset. |
SecretKey |
generateSecret(String algorithm)
Generates the shared secret.
|
String |
getAlgorithm()
Returns the name of the key agreement algorithm.
|
KeyAgreementSpi |
getCurrentSpi()
Returns the
KeyAgreementSpi backing this KeyAgreement or null if no
KeyAgreementSpi is backing this KeyAgreement. |
static KeyAgreement |
getInstance(String algorithm)
Creates a new
KeyAgreement for the specified algorithm. |
static KeyAgreement |
getInstance(String algorithm,
Provider provider)
Create a new
KeyAgreement for the specified algorithm from the
specified provider. |
static KeyAgreement |
getInstance(String algorithm,
String provider)
Creates a new
KeyAgreement for the specified algorithm from the
specified provider. |
Provider |
getProvider()
Returns the provider for this
KeyAgreement instance. |
void |
init(Key key)
Initializes this
KeyAgreement with the specified key. |
void |
init(Key key,
AlgorithmParameterSpec params)
Initializes this
KeyAgreement with the specified key and the
algorithm parameters. |
void |
init(Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Initializes this
KeyAgreement with the specified key, algorithm
parameters and randomness source. |
void |
init(Key key,
SecureRandom random)
Initializes this
KeyAgreement with the specified key and the
specified randomness source. |
protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider, String algorithm)
KeyAgreement instance.keyAgreeSpi - the SPI delegate.provider - the provider providing this KeyAgreement.algorithm - the name of the key agreement algorithm.public final String getAlgorithm()
public final Provider getProvider()
KeyAgreement instance.KeyAgreement instance.public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException
KeyAgreement for the specified algorithm.algorithm - the name of the key agreement algorithm to create.NoSuchAlgorithmException - if no installed provider can provide the requested algorithm.NullPointerException - if the specified algorithm is null.public static final KeyAgreement getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
KeyAgreement for the specified algorithm from the
specified provider.algorithm - the name of the key agreement algorithm to create.provider - the name of the provider that provides the requested
algorithm.NoSuchAlgorithmException - if the specified provider cannot provide the requested
algorithm.NoSuchProviderException - if the specified provider does not exist.IllegalArgumentException - if the specified provider name is null or empty.public static final KeyAgreement getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
KeyAgreement for the specified algorithm from the
specified provider. The provider supplied does not have to be
registered.algorithm - the name of the key agreement algorithm to create.provider - the provider that provides the requested algorithm.NoSuchAlgorithmException - if the specified provider cannot provide the requested
algorithm.IllegalArgumentException - if the specified provider is null.NullPointerException - if the specified algorithm name is null.public KeyAgreementSpi getCurrentSpi()
KeyAgreementSpi backing this KeyAgreement or null if no
KeyAgreementSpi is backing this KeyAgreement.public final void init(Key key) throws InvalidKeyException
KeyAgreement with the specified key.key - the key to initialize this key agreement.InvalidKeyException - if the specified key cannot be used to
initialize this key agreement.public final void init(Key key, SecureRandom random) throws InvalidKeyException
KeyAgreement with the specified key and the
specified randomness source.key - the key to initialize this key agreement.random - the source for any randomness needed.InvalidKeyException - if the specified key cannot be used to initialize this key
agreement.public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException
KeyAgreement with the specified key and the
algorithm parameters.key - the key to initialize this key agreement.params - the parameters for this key agreement algorithm.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.public final void init(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
KeyAgreement with the specified key, algorithm
parameters and randomness source.key - the key to initialize this key agreement.params - the parameters for this key agreement algorithm.random - the source for any randomness needed.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.public final Key doPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException
key - the key received from the other party for this phase.lastPhase - set to true if this is the last phase of this key
agreement.null if there is
no intermediate key for this phase.InvalidKeyException - if the specified key cannot be used in this key agreement or
this phase,IllegalStateException - if this instance has not been initialized.public final byte[] generateSecret()
throws IllegalStateException
IllegalStateException - if this key agreement is not complete.public final int generateSecret(byte[] sharedSecret,
int offset)
throws IllegalStateException,
ShortBufferException
sharedSecred at offset.sharedSecret - the buffer to store the shared secret.offset - the offset in the buffer.IllegalStateException - if this key agreement is not complete.ShortBufferException - if the specified buffer is too small for the shared secret.public final SecretKey generateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException
algorithm - the algorithm to for the SecretKeySecretKey of the specified
algorithm.IllegalStateException - if this key agreement is not complete.NoSuchAlgorithmException - if the specified algorithm for the secret key does not
exists.InvalidKeyException - if a SecretKey with the specified algorithm cannot be
created using the generated shared secret.