public class KeyAgreement extends java.lang.Object
The most common form of key agreement used today is the Diffie-Hellman key exchange algorithm, described in PKCS #3 - Diffie Hellman Key Agreement Standard.
KeyGenerator,
SecretKey| Modifier | Constructor and Description |
|---|---|
protected |
KeyAgreement(KeyAgreementSpi kaSpi,
java.security.Provider provider,
java.lang.String algorithm) |
| Modifier and Type | Method and Description |
|---|---|
java.security.Key |
doPhase(java.security.Key key,
boolean lastPhase)
Do a phase in the key agreement.
|
byte[] |
generateSecret()
Generate the shared secret in a new byte array.
|
int |
generateSecret(byte[] sharedSecret,
int offset)
Generate the shared secret and store it into the supplied array.
|
SecretKey |
generateSecret(java.lang.String algorithm)
Generate the shared secret and return it as an appropriate
SecretKey. |
java.lang.String |
getAlgorithm()
Return the name of this key-agreement algorithm.
|
static KeyAgreement |
getInstance(java.lang.String algorithm)
Get an implementation of an algorithm from the first provider that
implements it.
|
static KeyAgreement |
getInstance(java.lang.String algorithm,
java.security.Provider provider)
Return an implementation of an algorithm from a specific provider.
|
static KeyAgreement |
getInstance(java.lang.String algorithm,
java.lang.String provider)
Return an implementation of an algorithm from a named provider.
|
java.security.Provider |
getProvider()
Return the provider of the underlying implementation.
|
void |
init(java.security.Key key)
Initialize this key agreement with a key.
|
void |
init(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Initialize this key agreement with a key and parameters.
|
void |
init(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initialize this key agreement with a key, parameters, and source of
randomness.
|
void |
init(java.security.Key key,
java.security.SecureRandom random)
Initialize this key agreement with a key and a source of
randomness.
|
protected KeyAgreement(KeyAgreementSpi kaSpi, java.security.Provider provider, java.lang.String algorithm)
public static final KeyAgreement getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
algorithm - The name of the algorithm to get.java.security.NoSuchAlgorithmException - If the specified algorithm is not
implemented by any installed provider.java.lang.IllegalArgumentException - if algorithm is
null or is an empty string.public static final KeyAgreement getInstance(java.lang.String algorithm, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
algorithm - The name of the algorithm to create.provider - The name of the provider from which to get the
implementation.java.security.NoSuchAlgorithmException - If the named provider does not implement
the algorithm.java.security.NoSuchProviderException - If the named provider does not exist.java.lang.IllegalArgumentException - if either algorithm or
provider is null, or if
algorithm is an empty string.public static final KeyAgreement getInstance(java.lang.String algorithm, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
algorithm - The name of the algorithm to get.provider - The provider from which to get the implementation.java.security.NoSuchAlgorithmException - If this provider does not implement the
algorithm.java.lang.IllegalArgumentException - if either algorithm or
provider is null, or if
algorithm is an empty string.public final java.security.Key doPhase(java.security.Key key, boolean lastPhase) throws java.lang.IllegalStateException, java.security.InvalidKeyException
lastPhase flag set to true.key - The key for this phase.lastPhase - Should be true if this will be the
last phase before generating the shared secret.null if there is
no intermediate result.java.lang.IllegalStateException - If this instance has not
been initialized.java.security.InvalidKeyException - If the key is
inappropriate for this algorithm.public final byte[] generateSecret() throws java.lang.IllegalStateException
java.lang.IllegalStateException - If this instnace has not
been initialized, or if not enough calls to
doPhase have been made.public final int generateSecret(byte[] sharedSecret, int offset) throws java.lang.IllegalStateException, ShortBufferException
sharedSecret - The array in which to store the secret.offset - The index in sharedSecret to start
storing data.java.lang.IllegalStateException - If this instnace has not
been initialized, or if not enough calls to
doPhase have been made.ShortBufferException - If the supplied array is
not large enough to store the result.public final SecretKey generateSecret(java.lang.String algorithm) throws java.lang.IllegalStateException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException
SecretKey.algorithm - The secret key's algorithm.java.lang.IllegalStateException - If this instnace has not
been initialized, or if not enough calls to
doPhase have been made.java.security.InvalidKeyException - If the shared secret
cannot be used to make a SecretKey.java.security.NoSuchAlgorithmException - If the specified
algorithm does not exist.public final java.lang.String getAlgorithm()
public final java.security.Provider getProvider()
public final void init(java.security.Key key) throws java.security.InvalidKeyException
SecureRandom as its source
of randomness.key - The key, usually the user's private key.java.security.InvalidKeyException - If the supplied key is
not appropriate.public final void init(java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
key - The key, usually the user's private key.random - The source of randomness.java.security.InvalidKeyException - If the supplied key is
not appropriate.public final void init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidAlgorithmParameterException, java.security.InvalidKeyException
SecureRandom as its source of randomness.key - The key, usually the user's private key.params - The algorithm parameters.java.security.InvalidAlgorithmParameterException - If the
supplied parameters are not appropriate.java.security.InvalidKeyException - If the supplied key is
not appropriate.public final void init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidAlgorithmParameterException, java.security.InvalidKeyException
key - The key, usually the user's private key.params - The algorithm parameters.random - The source of randomness.java.security.InvalidAlgorithmParameterException - If the
supplied parameters are not appropriate.java.security.InvalidKeyException - If the supplied key is
not appropriate.