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.

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

Exceptions:
InvalidKeyException    if the given key is inappropriate for this phase.
IllegalStateException    if this key agreement has not been initialized.