com.motorola.iden.crypto
Class KeyAgreement

java.lang.Object
  |
  +--com.motorola.iden.crypto.KeyAgreement

public class KeyAgreement
extends java.lang.Object

This class provides the functionality of a key agreement (or key exchange) protocol. 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.

MOTOROLA and the Stylized M Logo are registered trademarks of Motorola, Inc. Reg. U.S. Pat. & Tm. Off.
© Copyright 2002 - 2004 Motorola, Inc. All Rights Reserved.

See Also:
[KeyAgreementSpi]

Constructor Summary
protected KeyAgreement(KeyAgreementSpi keyagreementspi)
          Creates a KeyAgreement object.
 
Method Summary
 Key doPhase(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()
          Generates the shared secret and returns it in a new buffer.
static KeyAgreement getInstance(java.lang.String algorithm)
          Generates a KeyAgreement object that implements the specified key agreement algorithm.
 void init(Key key, AlgorithmParameterSpec params)
          Initializes this key agreement with the given key and set of algorithm parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyAgreement

protected KeyAgreement(KeyAgreementSpi keyagreementspi)
Creates a KeyAgreement object.

Parameters:
keypairgeneratorspi - the instance of an algorithm which implements KeyAgreementSpi
Method Detail

getInstance

public static KeyAgreement getInstance(java.lang.String algorithm)
                                throws NoSuchAlgorithmException
Generates a KeyAgreement object that implements the specified key agreement algorithm. If the default provider package provides an implementation of the requested key agreement algorithm, an instance of KeyAgreement containing that implementation is returned. If the algorithm is not available in the default provider package, other provider packages are searched.
Parameters:
algorithm - the standard name of the requested key agreement algorithm. Algorithm DH and ECDH are supported in current implementation.
Returns:
the new KeyAgreement object
Throws:
NoSuchAlgorithmException - if the specified algorithm is not available in the default provider package or any of the other provider packages that were searched.

init

public final void init(Key key,
                       AlgorithmParameterSpec params)
                throws InvalidKeyException,
                       InvalidAlgorithmParameterException
Initializes this key agreement with the given key and set of algorithm parameters.
Parameters:
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 parameters
Throws:
InvalidKeyException - if the given key is inappropriate for this key agreement, e.g., is of the wrong type or has an incompatible algorithm type.
InvalidAlgorithmParameterException - if the given parameters are inappropriate for this key agreement.

doPhase

public final Key doPhase(Key key,
                         boolean lastPhase)
                  throws InvalidKeyException
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.
Parameters:
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.
Returns:
the (intermediate) key resulting from this phase, or null if this phase does not yield a key
Throws:
InvalidKeyException - if the given key is inappropriate for this phase.

generateSecret

public final byte[] generateSecret()
Generates the shared secret and returns it in a new buffer.

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.

Returns:
the new buffer with the shared secret