h49450 s 00038/00201/00292 d D 1.6 97/12/09 15:24:46 luehe 7 6 c rm ,* e s 00004/00004/00489 d D 1.5 97/11/18 08:49:06 luehe 6 5 c replaced "Architecture" with "Extension" when referring to API Spec & Reference Guide e s 00004/00004/00489 d D 1.4 97/11/17 13:31:22 luehe 5 4 c removed "#ApplA" from anchor reference e s 00003/00049/00490 d D 1.3 97/10/18 14:18:37 luehe 4 3 c moved javadocs example to JCESpec document (just to be safe ...) e s 00002/00003/00537 d D 1.2 97/10/10 12:42:06 luehe 3 1 c fixed getProvider javadocs e s 00000/00000/00000 d R 1.2 97/10/09 09:58:15 Codemgr 2 1 c SunPro Code Manager data about conflicts, renames, etc... c Name history : 1 0 security/JCE1.2/earlyaccess/javax.crypto.KeyAgreement.html e s 00540/00000/00000 d D 1.1 97/10/09 09:58:14 luehe 1 0 c date and time created 97/10/09 09:58:14 by luehe e u U f e 0 t T I 1
D 3 E 3 I 3 D 4 E 4 I 4 D 7 E 7 I 7 E 7 E 4 E 3D 4 All Packages Class Hierarchy This Package Previous Next IndexE 4 I 4 D 7 All Packages Class Hierarchy This Package Previous Next Index E 7 I 7 All Packages Class Hierarchy This Package Previous Next Index E 7 E 4
java.lang.Object | +----javax.crypto.KeyAgreement
KeyPairGenerator
or
KeyGenerator
), a KeyFactory
, or as a result from
an intermediate phase of the key agreement protocol (see doPhase).
D 4
The following sequence of calls illustrates a Diffie-Hellman key agreement between two parties, Alice and Bob, including the generation of Diffie-Hellman parameters by Alice. In Phase 1 of the Diffie-Hellman protocol, Alice and Bob use the Diffie-Hellman parameters generated by Alice to produce a public value and a private value. In Phase 2, they trade public values and each uses the other's public value with their own private value to generate the same secret value. This example describes the key agreement protocol from Alice's perspective.
import java.security.*; import java.security.spec.*;E 4 D 7// ALICE: creates her own Diffie-Hellman key pair; she chooses a prime // modulus size of 1024 bits. As part of the key pair generation process, // Diffie-Hellman parameters are created, too. KeyPairGenerator dhKeyPairGenerator = KeyPairGenerator.getInstance("DH"); dhKeyPairGenerator.initialize(1024); KeyPair dhKeyPair = dhKeyPairGenerator.generateKeyPair();
// ALICE: transmits her public key (in encoded format) to Bob. The encoded // key also contains her Diffie-Hellman parameters. byte[] dhPubKeyEncoded = dhKeyPair.getPublic().getEncoded(); // send to Bob
// ALICE: initiates her version of the key agreement protocol with her own // private value KeyAgreement dhKeyAgree = KeyAgreement.getInstance("DH"); dhKeyAgree.doPhase(1, dhKeyPair.getPrivate());
// Meanwhile, Bob has created his own Diffie-Hellman key pair. He has // initialized his key pair generator with the Diffie-Hellman parameters // that he retrieved from Alice's public key. // Bob sends his own public value (in encoded format) to Alice.
// ALICE: uses the appropriate key factory to convert the encoding of Bob's // key into a
PublicKey
KeyFactory dhKeyFactory = KeyFactory.getInstance("DH"); X509EncodedKeySpec dhBobPubKeySpec = new X509EncodedKeySpec (dhBobPubKeyEncoded); PublicKey dhBobPubKey = dhKeyFactory.generatePublic(dhBobPubKeySpec);// ALICE: completes her version of the key agreement protocol dhKeyAgree.doPhase(2, dhBobPubKey);
// ALICE: generates the shared secret byte[] secret = dhKeyAgree.generateSecret();
The methods of KeyAgreement
are divided into two groups:
engineGenerateSecret
is called by generateSecret
.
KeyAgreement
object for the specified key
agreement algorithm.
E 7
I 7
KeyAgreement(KeyAgreementSpi, Provider, String)
phase
of the key agreement
protocol, using the provided key key
.
phase
of the key
agreement protocol, using the provided key key
.
sharedSecret
, beginning at offset
.
random
.
sharedSecret
, beginning at offset
.
KeyAgreement
object for the specified key
agreement algorithm.
KeyAgreement
object for the specified key
agreement algorithm from the specified provider.
KeyAgreement
object.
random
.
D 7 protected KeyAgreement(String algorithm) E 7 I 7 protected KeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider, String algorithm) E 7
KeyAgreement
object for the specified key
agreement algorithm.
E 7
I 7
public final String getAlgorithm()
D 7 public static KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException E 7 I 7 public static final KeyAgreement getInstance(String algorithm) throws NoSuchAlgorithmException E 7
KeyAgreement
object for the specified key
agreement algorithm.
KeyAgreement
object
D 7 public static KeyAgreement getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException E 7 I 7 public static final KeyAgreement getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException E 7
KeyAgreement
object for the specified key
agreement algorithm from the specified provider.
KeyAgreement
object
public final Provider getProvider()
KeyAgreement
object.
KeyAgreement
object,
or null if the provider has not yet been set
E 3
I 3
KeyAgreement
object
E 3
D 7 public void init(SecureRandom random) E 7 I 7 public final void init(SecureRandom random) E 7
random
. If the underlying implementation does not require
any random bytes, random
is ignored.
protected abstract void engineInit(SecureRandom random)
random
.
D 7 public void init(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException E 7 I 7 public final void init(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException E 7
D 7 public void init(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException E 7 I 7 public final void init(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException E 7
protected abstract void engineInit(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException
D 7 public Key doPhase(int phase, Key key) throws IllegalStateException, InvalidKeyException E 7 I 7 public final Key doPhase(int phase, Key key) throws IllegalStateException, InvalidKeyException E 7
phase
of the key agreement
protocol, using the provided key key
.
phase
, or null if
phase
does not yield a key
phase
is
inappropriate for this key agreement protocol, or does not correspond to
the next phase in the protocol sequence
phase
protected abstract Key engineDoPhase(int phase, Key key) throws IllegalStateException, InvalidKeyException
phase
of the key
agreement protocol, using the provided key key
.
phase
, or null if
phase
does not yield a key
phase
is
inappropriate for this key agreement protocol, or does not correspond to
the next phase in the protocol sequence
phase
D 7 public byte[] generateSecret() throws IllegalStateException E 7 I 7 public final byte[] generateSecret() throws IllegalStateException E 7
The key agreement is reset to its initial state after this call.
protected abstract byte[] engineGenerateSecret() throws IllegalStateException
The key agreement is reset to its initial state after this call.
D 7 public int generateSecret(byte sharedSecret[], int offset) throws IllegalStateException E 7 I 7 public final int generateSecret(byte sharedSecret[], int offset) throws IllegalStateException, ShortBufferException E 7
sharedSecret
, beginning at offset
.
D 7
The key agreement is reset to its initial state after this call. E 7 I 7
If the sharedSecret
buffer is too small to hold the
result, a ShortBufferException
is thrown.
In this case, this call should be repeated with a larger output buffer.
After this call has completed successfully, this
KeyAgreement
is reset to its initial state
(uninitialized), and can be re-used for further key agreements.
E 7
sharedSecret
where the
shared secret will be stored
sharedSecret
protected abstract int engineGenerateSecret(byte sharedSecret[], int offset) throws IllegalStateException
sharedSecret
, beginning at offset
.
The key agreement is reset to its initial state after this call.
sharedSecret
where the
shared secret will be stored
sharedSecret
public int getSecretSize()
protected abstract int engineGetSecretSize()
D 4 All Packages Class Hierarchy This Package Previous Next IndexE 4 I 4 D 7 All Packages Class Hierarchy This Package Previous Next Index E 7 I 7 All Packages Class Hierarchy This Package Previous Next Index E 7 E 4 E 1