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.
For each of the correspondents in the key exchange, doPhase
needs to be called. For example, if this key exchange is with one other
party, doPhase needs to be called once, with the
lastPhase flag set to true.
If this key exchange is
with two other parties, doPhase needs to be called twice,
the first time setting the lastPhase flag to
false, and the second time setting it to true.
There may be any number of parties involved in a key exchange. However,
support for key exchanges with more than two parties is implementation
specific or as specified by the standard key agreement algorithm.
Every implementation of the Java platform is required to support the
following standard KeyAgreement algorithms. For the "ECDH"
algorithm, implementations must support the curves in parentheses.
DiffieHellmanECDH (secp256r1, secp384r1)X25519KeyGenerator, SecretKey
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private static final Debug | |
| private Provider. | |
| private static final int | |
| private static final int | |
| private final Object | |
| private static final Debug | |
| private Provider | |
| private Iterator | |
| private static final boolean | |
| private KeyAgreementSpi | |
| private static int |
| Access | Constructor and Description |
|---|---|
| protected | KeyAgreement(KeyAgreementSpi
the delegate keyAgreeSpi, Provider the provider provider, String the algorithm algorithm)Creates a |
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| private void | |
| public final Key | Returns: the (intermediate) key resulting from this phase, ornull
if this phase does not yield a keythe key for this phase. For example, in the case of
Diffie-Hellman between 2 parties, this would be the other party's
Diffie-Hellman public key. key, boolean flag which indicates whether this is the last
phase of this key agreement. lastPhase)Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement. |
| public final byte[] | Returns: the new buffer with the shared secretGenerates the shared secret and returns it in a new buffer. |
| public final int | Returns: the number of bytes placed intosharedSecretthe buffer for the shared secret sharedSecret, int the offset in offset)sharedSecret where the
shared secret will be storedGenerates the shared secret, and places it into the buffer
|
| public final SecretKey | Returns: the shared secret key. The length of the key material may be adjusted to be compatible with the specified algorithm, regardless of whether the key is extractable. Ifalgorithm
is specified as "Generic" and it is supported by the implementation,
the full shared secret is returned.the requested secret key algorithm. This is different
from the algorithm)KeyAgreement algorithm provided to the
getInstance method. See the SecretKey Algorithms section in the
Java Security Standard Algorithm Names Specification
for information about standard secret key algorithm names.
Specify "Generic" if the output will be used as the input keying
material of a key derivation function (KDF).Creates the shared secret and returns it as a |
| public final String | Returns: the algorithm name of thisKeyAgreement object.Returns the algorithm name of this |
| public static final KeyAgreement | Returns: the newKeyAgreement objectthe standard name of the requested key agreement
algorithm.
See the KeyAgreement section in the
Java Security Standard Algorithm Names Specification
for information about standard algorithm names. algorithm)Returns a |
| public static final KeyAgreement | Returns: the newKeyAgreement objectthe standard name of the requested key agreement
algorithm.
See the KeyAgreement section in the
Java Security Standard Algorithm Names Specification
for information about standard algorithm names. algorithm, String the name of the provider. provider)Returns a |
| public static final KeyAgreement | Returns: the newKeyAgreement objectthe standard name of the requested key agreement
algorithm.
See the KeyAgreement section in the
Java Security Standard Algorithm Names Specification
for information about standard algorithm names. algorithm, Provider the provider. provider)Returns a |
| public final Provider | Returns: the provider of thisKeyAgreement objectReturns the provider of this |
| private String | |
| private void | implInit(KeyAgreementSpi spi, int type, Key key, AlgorithmParameterSpec params, SecureRandom random)
|
| public final void | init(Key
the party's private information. For example, in the case
of the Diffie-Hellman key agreement, this would be the party's own
Diffie-Hellman private key. key)Initializes this key agreement with the given key, which is required to contain all the algorithm parameters required for this key agreement. |
| public final void | init(Key
the party's private information. For example, in the case
of the Diffie-Hellman key agreement, this would be the party's own
Diffie-Hellman private key. key, SecureRandom the source of randomness random)Initializes this key agreement with the given key and source of randomness. |
| public final void | init(Key
the party's private information. For example, in the case
of the Diffie-Hellman key agreement, this would be the party's own
Diffie-Hellman private key. key, AlgorithmParameterSpec the key agreement parameters params)Initializes this key agreement with the given key and set of algorithm parameters. |
| public final void | init(Key
the party's private information. For example, in the case
of the Diffie-Hellman key agreement, this would be the party's own
Diffie-Hellman private key. key, AlgorithmParameterSpec the key agreement parameters params, SecureRandom the source of randomness random)Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness. |
| algorithm | back to summary |
|---|---|
| private final String algorithm | |
| debug | back to summary |
|---|---|
| private static final Debug debug | |
| firstService | back to summary |
|---|---|
| private Provider. | |
| I_NO_PARAMS | back to summary |
|---|---|
| private static final int I_NO_PARAMS | |
| I_PARAMS | back to summary |
|---|---|
| private static final int I_PARAMS | |
| lock | back to summary |
|---|---|
| private final Object lock | |
| pdebug | back to summary |
|---|---|
| private static final Debug pdebug | |
| provider | back to summary |
|---|---|
| private Provider provider | |
| serviceIterator | back to summary |
|---|---|
| private Iterator<Provider. | |
| skipDebug | back to summary |
|---|---|
| private static final boolean skipDebug | |
| spi | back to summary |
|---|---|
| private KeyAgreementSpi spi | |
| warnCount | back to summary |
|---|---|
| private static int warnCount | |
| KeyAgreement | back to summary |
|---|---|
| protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider, String algorithm) Creates a
| |
| KeyAgreement | back to summary |
|---|---|
| private KeyAgreement(Provider. | |
| chooseFirstProvider | back to summary |
|---|---|
| pack-priv void chooseFirstProvider() Choose the Spi from the first provider available. Used if delayed provider selection is not possible because init() is not the first method called. | |
| chooseProvider | back to summary |
|---|---|
| private void chooseProvider(int initType, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException | |
| doPhase | back to summary |
|---|---|
| public final Key doPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.
| |
| generateSecret | back to summary |
|---|---|
| public final byte[] generateSecret() throws IllegalStateException Generates the shared secret and returns it in a new buffer. This method resets this
| |
| generateSecret | back to summary |
|---|---|
| public final int generateSecret(byte[] sharedSecret, int offset) throws IllegalStateException, ShortBufferException Generates the shared secret, and places it into the buffer
If the This method resets this
| |
| generateSecret | back to summary |
|---|---|
| public final SecretKey generateSecret(String algorithm) throws IllegalStateException, NoSuchAlgorithmException, InvalidKeyException Creates the shared secret and returns it as a This method resets this
| |
| getAlgorithm | back to summary |
|---|---|
| public final String getAlgorithm() Returns the algorithm name of this This is the same name that was specified in one of the
| |
| getInstance | back to summary |
|---|---|
| public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException Returns a This method traverses the list of registered security providers,
starting with the most preferred provider.
A new Note that the list of registered providers may be retrieved via
the Implementation Note The JDK Reference Implementation additionally uses the
| |
| getInstance | back to summary |
|---|---|
| public static final KeyAgreement getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException Returns a A new Note that the list of registered providers may be retrieved via
the
| |
| getInstance | back to summary |
|---|---|
| public static final KeyAgreement getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException Returns a A new
| |
| getProvider | back to summary |
|---|---|
| public final Provider getProvider() Returns the provider of this
| |
| getProviderName | back to summary |
|---|---|
| private String getProviderName() | |
| implInit | back to summary |
|---|---|
| private void implInit(KeyAgreementSpi spi, int type, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException | |
| init | back to summary |
|---|---|
| public final void init(Key key) throws InvalidKeyException Initializes this key agreement with the given key, which is required to contain all the algorithm parameters required for this key agreement. If this key agreement requires any random bytes, it will get
them using the
| |
| init | back to summary |
|---|---|
| public final void init(Key key, SecureRandom random) throws InvalidKeyException Initializes this key agreement with the given key and source of randomness. The given key is required to contain all the algorithm parameters required for this key agreement. If the key agreement algorithm requires random bytes, it gets them
from the given source of randomness,
| |
| init | back to summary |
|---|---|
| public final void init(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException Initializes this key agreement with the given key and set of algorithm parameters. If this key agreement requires any random bytes, it will get
them using the
| |
| init | back to summary |
|---|---|
| public final void init(Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness.
| |