Constructor and Description |
---|
KeyAgreement(java.lang.String algorithm)
ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
clean()
clean all important content.
|
java.security.Key |
doPhase(java.security.Key key,
boolean 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.
|
byte[] |
generateSecret()
Unsupported operation, pure secret key as byte[] forbidden.
|
int |
generateSecret(byte[] sharedSecret,
int offset)
Unsupported operation, pure secret key as byte[] forbidden.
|
javax.crypto.SecretKey |
generateSecret(java.lang.String algorithm)
Creates the shared secret and returns it as a
SecretKey object of the specified algorithm. |
java.lang.String |
getAlgorithm()
Returns the algorithm name of this
KeyAgreement object. |
static KeyAgreement |
getInstance(java.lang.String algorithm)
Algorithm factory, create object by algorithm name.
|
static KeyAgreement |
getInstance(java.lang.String algorithm,
java.security.Provider provider)
Algorithm factory, create object by algorithm name.
|
static KeyAgreement |
getInstance(java.lang.String algorithm,
java.lang.String provider)
Algorithm factory, create object by algorithm name.
|
java.security.Provider |
getProvider()
Returns the provider of this
KeyAgreement object. |
void |
init(java.security.Key key)
Initializes this key agreement with the given key, which is required to
contain all the algorithm parameters required for this key agreement.
|
void |
init(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Initializes this key agreement with the given key and set of algorithm parameters.
|
void |
init(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this key agreement with the given key, set of algorithm parameters, and source of randomness.
|
void |
init(java.security.Key key,
java.security.SecureRandom random)
Initializes this key agreement with the given key and source of randomness.
|
public static KeyAgreement getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
KeyAgreement.getInstance(String)
.algorithm
- algorithm name.java.security.NoSuchAlgorithmException
- if the specified algorithm is not availablepublic static KeyAgreement getInstance(java.lang.String algorithm, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
KeyAgreement.getInstance(String, String)
.algorithm
- algorithm name.provider
- unusedjava.security.NoSuchAlgorithmException
- if the specified algorithm is not availablejava.security.NoSuchProviderException
- if the specified provider is not availablepublic static KeyAgreement getInstance(java.lang.String algorithm, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
KeyAgreement.getInstance(String, Provider)
.algorithm
- algorithm name.provider
- unusedjava.security.NoSuchAlgorithmException
- if the specified algorithm is not availablepublic java.lang.String getAlgorithm()
KeyAgreement
object.
This is the same name that was specified in one of the getInstance
calls
that created this KeyAgreement
object.KeyAgreement
object.public java.security.Provider getProvider()
KeyAgreement
object.KeyAgreement
objectpublic void init(java.security.Key key) throws java.security.InvalidKeyException
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.java.security.InvalidKeyException
- if the given key is inappropriate for this key agreement,
e.g., is of the wrong type or has an incompatible algorithm type.public void init(java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
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.random
- the source of randomnessjava.security.InvalidKeyException
- if the given key is inappropriate for this key agreement,
e.g., is of the wrong type or has an incompatible algorithm type.public void init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
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.params
- the key agreement parametersjava.security.InvalidKeyException
- if the given key is inappropriate for this key agreement,
e.g., is of the wrong type or has an incompatible algorithm type.java.security.InvalidAlgorithmParameterException
- if the given parameters are inappropriate for this key agreement.public void init(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
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.params
- the key agreement parametersrandom
- the source of randomnessjava.security.InvalidKeyException
- if the given key is inappropriate for this key agreement,
e.g., is of the wrong type or has an incompatible algorithm type.java.security.InvalidAlgorithmParameterException
- if the given parameters are inappropriate for this key agreement.public java.security.Key doPhase(java.security.Key key, boolean lastPhase) throws java.security.InvalidKeyException, java.lang.IllegalStateException
key
- the 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.lastPhase
- flag which indicates whether or not this is the last phase of this key agreement.java.security.InvalidKeyException
- if the given key is inappropriate for this phase.java.lang.IllegalStateException
- if this key agreement has not been initialized.public byte[] generateSecret() throws java.lang.IllegalStateException
java.lang.UnsupportedOperationException
- alwaysjava.lang.IllegalStateException
- if this key agreement has not been completed yetpublic int generateSecret(byte[] sharedSecret, int offset) throws java.lang.IllegalStateException, javax.crypto.ShortBufferException
sharedSecret
, beginning at offset
inclusive.sharedSecret
- the buffer for the shared secretoffset
- the offset in sharedSecret
where the shared secret will be storedsharedSecret
java.lang.UnsupportedOperationException
- alwaysjava.lang.IllegalStateException
- if this key agreement has not been completed yetjavax.crypto.ShortBufferException
- if the given output buffer is too small to hold the secretpublic javax.crypto.SecretKey generateSecret(java.lang.String algorithm) throws java.lang.IllegalStateException, java.security.NoSuchAlgorithmException, java.security.InvalidKeyException
SecretKey
object of the specified algorithm.
This method resets this KeyAgreement
object, so that it can be reused for further key agreements.
Unless this key agreement is reinitialized with one of the init
methods,
the same private information and algorithm parameters will be used for subsequent key agreements.algorithm
- the requested secret-key algorithmjava.lang.IllegalStateException
- if this key agreement has not been completed yetjava.security.NoSuchAlgorithmException
- if the specified secret-key algorithm is not availablejava.security.InvalidKeyException
- if the shared secret-key material cannot be used to generate a secret key
of the specified algorithm (e.g., the key material is too short)