com.rsa.jsafe
Class JSAFE_KeyAgree

java.lang.Object
  extended bycom.rsa.jsafe.JSAFE_Object
      extended bycom.rsa.jsafe.JSAFE_KeyAgree
All Implemented Interfaces:
Cloneable, Serializable

public abstract class JSAFE_KeyAgree
extends JSAFE_Object
implements Cloneable, Serializable

The JSAFE_KeyAgree class defines the factory method and API for the key agreement algorithms. This class can instantiate the classes that perform key agreement and defines the functionality. Currently, Crypto-J only supports Diffie-Hellman key agreement.

See Overview of Crypto-J for background and reference material on using and understanding Crypto-J.

Note: Not all Crypto-J transformations have OIDs assigned to them. See Crypto-J Transformations and Their Associated Classes for a list of transformations that have assigned OIDs.

Copyright © RSA Security Inc., 1997-2005. All rights reserved.

See Also:
Serialized Form

Constructor Summary
JSAFE_KeyAgree()

 

 
Method Summary

 void

clearSensitiveData()

This method clears sensitive data from an object.

abstract  JSAFE_PublicKey

generateMyPublicValue()

Generates the public value, using key-based key agreement methods in the form of JSAFE_PublicKey.

 byte[]

generateSharedSecret()

Computes the shared secret and returns it in a new byte array.

abstract  int

generateSharedSecret(byte[] sharedSecret, int offset)

Computes the shared secret and places it in the byte array sharedSecret beginning at offset.

 byte[]

generateSharedSecret(JSAFE_PublicKey correspondentKey)

Computes the shared secret and returns it in a new byte array.

abstract  int

generateSharedSecret(JSAFE_PublicKey correspondentKey, byte[] sharedSecret, int offset)

Computes the shared secret and places it in the byte array sharedSecret, beginning at offset.

 JSAFE_KeyPair

getBlankKeyPair()

Returns a new, empty JSAFE_KeyPair object to match the algorithm and device of this object.

abstract  byte[]

getDERAlgorithmID()

Returns a new byte array containing the DER encoding of the key agreement algorithm identifier of the algorithm in this object.

 String

getDevice()

Returns the name of the device of record.

 String[]

getDeviceList()

Returns a String array that describes all the devices used to execute the transformation.

static JSAFE_KeyAgree

getInstance(byte[] berAlgID, int offset, String device)

Builds an object that performs an algorithm using the possible parameters defined in berAlgID.

static JSAFE_KeyAgree

getInstance(String transformation, String device)

Builds an object that performs the specified transformation on the given device.

abstract  String

getKeyAgreeAlgorithm()

Returns the standard name of the key agreement algorithm.

static int

getNextBEROffset(byte[] berAlgID, int offset)

Gets the next offset after the algorithm ID.

abstract  int

getOutputSize()

Returns the output size (in bytes) that results from a key-agreement operation.

 byte[]

getPrivateValue()

Retrieves the private value in a new byte array.

abstract  int

getPrivateValue(byte[] privateValue, int offset)

Retrieves the private value.

abstract  JSAFE_PrivateKey

getPrivateValueAsKey()

Returns a new JSAFE_PrivateKey object that contains the private value computed in generateMyPublicValue().

abstract  JSAFE_Parameters

getSharedParameters()

Returns a new JSAFE_Parameters object that contains the shared-key agreement parameters.

abstract  void

keyAgreeInit(JSAFE_Parameters sharedParameters, JSAFE_PrivateKey myKey, SecureRandom random)

Initializes an object to compute key-agreement values using sharedParameters and myKey.

abstract  void

keyAgreeInit(JSAFE_Parameters sharedParameters, JSAFE_PublicKey correspondentKey, SecureRandom random)

Initializes an object to compute key-agreement values using sharedParameters and correspondentKey.

abstract  void

keyAgreeInit(JSAFE_Parameters sharedParameters, SecureRandom random)

Initializes an object to compute key-agreement values using sharedParameters.

abstract  void

keyAgreeInit(JSAFE_PrivateKey myKey, SecureRandom random)

Initializes this object for key agreement using the private key specified by myKey.

abstract  void

keyAgreeInit(JSAFE_PublicKey correspondentKey, SecureRandom random)

Initializes an object to compute key-agreement values using correspondentKey.

abstract  void

keyAgreeInit(SecureRandom random)

Initializes an object to compute the key-agreement values using the parameters that were already loaded into an object.

 byte[]

keyAgreePhase1()

Performs Phase 1 of key agreement, generating a public value.

abstract  int

keyAgreePhase1(byte[] myPublicValue, int offset)

Performs Phase 1 of key agreement, generating a public value.

 byte[]

keyAgreePhase2(byte[] correspondentPublicValue, int offset, int len)

Performs Phase 2 of key agreement, generating the shared secret, using the private value generated during keyAgreePhase1() and the len bytes of correspondentPublicValue, beginning at offset.

abstract  int

keyAgreePhase2(byte[] correspondentPublicValue, int inOffset, int len, byte[] sharedSecret, int outOffset)

Performs Phase 2 of key agreement, computing the shared secret and placing it in the byte array sharedSecret, beginning at outOffset.

abstract  void

keyAgreeReInit()

Re-initializes the object to perform key agreement.

 
Methods inherited from class com.rsa.jsafe.JSAFE_Object
clone, overwrite, overwrite
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSAFE_KeyAgree

public JSAFE_KeyAgree()
Method Detail

getInstance

public static JSAFE_KeyAgree getInstance(byte[] berAlgID,
                                         int offset,
                                         String device)
                                  throws JSAFE_UnimplementedException,
                                         JSAFE_InvalidParameterException
Builds an object that performs an algorithm using the possible parameters defined in berAlgID. This is the BER encoding of the algorithm identifier. The specified device is used. The value encoded in berAlgID always follows the definition listed below.
 AlgorithmIdentifier ::=SEQUENCE {
    algorithm OBJECT IDENTIFIER,
    parameters ANY DEFINED BY algorithm OPTIONAL}
 

Parameters:
berAlgID - A byte array containing the BER encoding of an algorithm ID.
offset - The offset into berAlgID where the encoding begins.
device - A list of devices used to build the object.
Returns:
A new JSAFE_KeyAgree object that performs the transformation as described by the algorithm ID.
Throws:
JSAFE_UnimplementedException - If the device or devices cannot perform the designated algorithm, or if the toolkit cannot decode the BER encoding.
JSAFE_InvalidParameterException - If the BER encoding contains parameters that do not work.

getNextBEROffset

public static int getNextBEROffset(byte[] berAlgID,
                                   int offset)
                            throws JSAFE_UnimplementedException
Gets the next offset after the algorithm ID. Given the berAlgID, the BER encoding of the algorithm ID, beginning at offset, returns the index to the next byte in the array.

Parameters:
berAlgID - A byte array containing the BER encoding of an algorithm ID.
offset - The offset into berAlgID where the encoding begins.
Returns:
The index into berAlgID of the byte following the algorithm ID.
Throws:
JSAFE_UnimplementedException - If the toolkit cannot decode the BER encoding.

getInstance

public static JSAFE_KeyAgree getInstance(String transformation,
                                         String device)
                                  throws JSAFE_UnimplementedException,
                                         JSAFE_InvalidParameterException
Builds an object that performs the specified transformation on the given device. The value of the algorithm is "DH". The device value is as follows: "choice1[/choice2[...[/choicen]]]" where the choices are: Crypto-J tries to instantiate a class using the first choice; if it cannot, it tries the other choices.

Parameters:
transformation - The representation of the desired operation (for example, "DH").
device - A list of devices to use when building the object (for example, "Java", "Native/Java").
Returns:
A new JSAFE_KeyAgree object that performs the transformation.
Throws:
JSAFE_UnimplementedException - If the device or devices cannot perform the designated algorithm.
JSAFE_InvalidParameterException - If the transformation contains parameters that do not work.

getDERAlgorithmID

public abstract byte[] getDERAlgorithmID()
                                  throws JSAFE_UnimplementedException
Returns a new byte array containing the DER encoding of the key agreement algorithm identifier of the algorithm in this object.

Returns:
A new byte array that contains the algorithm ID.
Throws:
JSAFE_UnimplementedException - If the algorithm has no OID, or there is not enough information to build the algorithm ID.

getDevice

public String getDevice()
Returns the name of the device of record. Possible device values are:

Returns:
The device name.

getDeviceList

public String[] getDeviceList()
Returns a String array that describes all the devices used to execute the transformation. Because a transformation often consists of component algorithms, the implementation can consist of several component objects. A device can perform one or more of the algorithms, but it may let Java or another device perform one or more. For example, because padding is not time-consuming, a device might let the Crypto-J implementation perform padding.

Returns:
A String array that describes the device used for a specific component.

getKeyAgreeAlgorithm

public abstract String getKeyAgreeAlgorithm()
Returns the standard name of the key agreement algorithm.

Returns:
A String that describes the key agreement algorithm.

getSharedParameters

public abstract JSAFE_Parameters getSharedParameters()
                                              throws JSAFE_InvalidUseException
Returns a new JSAFE_Parameters object that contains the shared-key agreement parameters. If an object does not yet contain parameters, this method throws an exception. Gets the system parameters, if any.

Returns:
A JSAFE_Parameters object that contains the system parameters.
Throws:
JSAFE_InvalidUseException - If the object contains no system parameters.

getBlankKeyPair

public JSAFE_KeyPair getBlankKeyPair()
Returns a new, empty JSAFE_KeyPair object to match the algorithm and device of this object. This key-pair object may then be used to set or generate the key data.

Returns:
A new, empty JSAFE_KeyPair object.

getOutputSize

public abstract int getOutputSize()
Returns the output size (in bytes) that results from a key-agreement operation. Call this method only after entering the parameters of the key-agreement algorithm (either by calling a keyAgreeInit(), or at instantiation in the BER encoding of an algorithm identifier). Otherwise, the return value could be zero.

Returns:
An int that is the size of the output.

keyAgreeInit

public abstract void keyAgreeInit(SecureRandom random)
                           throws JSAFE_InvalidUseException
Initializes an object to compute the key-agreement values using the parameters that were already loaded into an object. These values are loaded at instantiation if BER encoding is used for the algorithm identifier, or if keyAgreeInit() was previously called. If an algorithm needs random bytes, the object gets them from random. JSAFE_SecureRandom is a subclass of java.security.SecureRandom, so an object of that class is valid input for random.

Parameters:
random - A SecureRandom object from which this object draws random bytes, if necessary.
Throws:
JSAFE_InvalidUseException - If the object does not yet possess system parameters.

keyAgreeInit

public abstract void keyAgreeInit(JSAFE_Parameters sharedParameters,
                                  SecureRandom random)
                           throws JSAFE_InvalidParameterException,
                                  JSAFE_InvalidUseException
Initializes an object to compute key-agreement values using sharedParameters. If an algorithm needs random bytes, an object gets them from random. JSAFE_SecureRandom is a subclass of java.security.SecureRandom, so an object of that class is valid input for random.

Parameters:
sharedParameters - A JSAFE_Parameters object containing the system parameters.
random - A SecureRandom object from which this object draws random bytes, if necessary.
Throws:
JSAFE_InvalidParameterException - If the shared parameters do not match the algorithm specified at instantiation.
JSAFE_InvalidUseException - If the object does not possess a random object.

keyAgreeInit

public abstract void keyAgreeInit(JSAFE_Parameters sharedParameters,
                                  JSAFE_PublicKey correspondentKey,
                                  SecureRandom random)
                           throws JSAFE_InvalidParameterException,
                                  JSAFE_InvalidKeyException,
                                  JSAFE_InvalidUseException

Initializes an object to compute key-agreement values using sharedParameters and correspondentKey. If an algorithm needs random bytes, an object gets them from random. JSAFE_SecureRandom is a subclass of java.security.SecureRandom so an object of that class is valid input for random.

Use this method to initiate a "key-based" key agreement with another party, the correspondent.

Parameters:
sharedParameters - A JSAFE_Parameters object containing the system parameters.
correspondentKey - The other party's key agreement public key.
random - A SecureRandom object from which this object draws random bytes if necessary.
Throws:
JSAFE_InvalidParameterException - If the shared parameters do not match the algorithm specified at instantiation.
JSAFE_InvalidKeyException - If the key does not match the algorithm or shared parameters.
JSAFE_InvalidUseException - If the object does not possess a random object.

keyAgreeInit

public abstract void keyAgreeInit(JSAFE_PublicKey correspondentKey,
                                  SecureRandom random)
                           throws JSAFE_InvalidKeyException,
                                  JSAFE_InvalidParameterException,
                                  JSAFE_InvalidUseException
Initializes an object to compute key-agreement values using correspondentKey. If an algorithm needs random bytes, an object gets them from random. JSAFE_SecureRandom is a subclass of java.security.SecureRandom, so an object of that class is valid input for random.

This method expects the system parameters to be already loaded. Use this method to initiate a "key-based" key agreement with another party, the correspondent.

Parameters:
correspondentKey - The other party's key agreement public key.
random - A SecureRandom object from which this object draws random bytes if necessary.
Throws:
JSAFE_InvalidParameterException - If the shared parameters do not match the algorithm specified at instantiation.
JSAFE_InvalidKeyException - If the key does not match the algorithm or shared parameters.
JSAFE_InvalidUseException - If the object does not possess system parameters or a random object.

keyAgreeInit

public abstract void keyAgreeInit(JSAFE_Parameters sharedParameters,
                                  JSAFE_PrivateKey myKey,
                                  SecureRandom random)
                           throws JSAFE_InvalidParameterException,
                                  JSAFE_InvalidKeyException,
                                  JSAFE_InvalidUseException
Initializes an object to compute key-agreement values using sharedParameters and myKey. If an algorithm needs random bytes, the object gets them from random. JSAFE_SecureRandom is a subclass of java.security.SecureRandom, so an object of that class is valid input for random.

If the private key does not contain the system parameters, this method will use those found in sharedParameters. If the private key does contain the system parameters, pass in null for this argument. Use this method to respond to a "key-based" key agreement.

Parameters:
sharedParameters - An object containing the system parameters.
myKey - The caller's key agreement private key.
random - A SecureRandom object from which this object will draw random bytes if necessary.
Throws:
JSAFE_InvalidParameterException - If the shared parameters do not match the algorithm specified at instantiation.
JSAFE_InvalidKeyException - If the key does not match the algorithm or shared parameters.
JSAFE_InvalidUseException - If the object does not possess a random object.

keyAgreeInit

public abstract void keyAgreeInit(JSAFE_PrivateKey myKey,
                                  SecureRandom random)
                           throws JSAFE_InvalidKeyException,
                                  JSAFE_InvalidParameterException,
                                  JSAFE_InvalidUseException
Initializes this object for key agreement using the private key specified by myKey. It computes key agreement values using myKey and certain parameters. These parameters either reside in the key object (if it was instantiated with parameters) or are already loaded into the object. This method expects the system parameters to already be loaded. This happens either at instantiation (if the BER encoding of the algorithm identifier is used), or by a previous call to keyAgreeInit().

If an algorithm needs random bytes, the object gets them from random. The JSAFE_SecureRandom object is a subclass of java.security.SecureRandom, so an object of that class is valid input for random.

Use this method to respond to a "key-based" key agreement.

Parameters:
myKey - The caller's key agreement private key.
random - A SecureRandom object this object draws random bytes from, if necessary.
Throws:
JSAFE_InvalidParameterException - If the shared parameters do not match the algorithm specified at instantiation.
JSAFE_InvalidKeyException - If the key does not match the algorithm or shared parameters.
JSAFE_InvalidUseException - If the object does not possess system parameters or a random object.

keyAgreeReInit

public abstract void keyAgreeReInit()
                             throws JSAFE_InvalidUseException
Re-initializes the object to perform key agreement. It uses the parameters that were already passed in by the previous call to a keyAgreeInit() method.

Throws:
JSAFE_InvalidUseException - If the object has not yet been initialized.

keyAgreePhase1

public byte[] keyAgreePhase1()
                      throws JSAFE_InvalidUseException
Performs Phase 1 of key agreement, generating a public value. Returns the public value in a new byte array.

Computes a private value and saves it in an object. Call getPrivateValue() to retrieve the private value.

Returns:
A new byte array containing the caller's public value.
Throws:
JSAFE_InvalidUseException - If the object is not yet initialized.
See Also:
getPrivateValue()

keyAgreePhase1

public abstract int keyAgreePhase1(byte[] myPublicValue,
                                   int offset)
                            throws JSAFE_InvalidUseException
Performs Phase 1 of key agreement, generating a public value. Places the public value into the given array myPublicValue, beginning at offset. The return value is the length of the public value, which is the number of bytes placed in the output buffer.

Computes a private value and saves it in an object. Call getPrivateValue() to retrieve the private value.

Parameters:
myPublicValue - The buffer where the output is placed.
offset - The offset into myPublicValue where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.
See Also:
getPrivateValue()

generateMyPublicValue

public abstract JSAFE_PublicKey generateMyPublicValue()
                                               throws JSAFE_InvalidUseException
Generates the public value, using key-based key agreement methods in the form of JSAFE_PublicKey. This is equivalent to Phase 1 when performing classical key agreement. Before this method is called, the object must have been initialized by a call to keyAgreeInit(). This method computes a private value and saves it in the algorithm object. To retrieve this private value, call getPrivateValue().

Returns:
A JSAFE_PublicKey object containing the public value (and the system parameters).
Throws:
JSAFE_InvalidUseException - If the object is not initialized for key-based key agreement.

keyAgreePhase2

public byte[] keyAgreePhase2(byte[] correspondentPublicValue,
                             int offset,
                             int len)
                      throws JSAFE_InvalidUseException
Performs Phase 2 of key agreement, generating the shared secret, using the private value generated during keyAgreePhase1() and the len bytes of correspondentPublicValue, beginning at offset. Returns the shared secret in a new byte array.

Parameters:
correspondentPublicValue - The other party's public value.
offset - The offset into correspondentPublicValue where the value begins.
len - The length of the other party's public value.
Returns:
A new byte array containing the shared secret.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.

keyAgreePhase2

public abstract int keyAgreePhase2(byte[] correspondentPublicValue,
                                   int inOffset,
                                   int len,
                                   byte[] sharedSecret,
                                   int outOffset)
                            throws JSAFE_InvalidUseException
Performs Phase 2 of key agreement, computing the shared secret and placing it in the byte array sharedSecret, beginning at outOffset. Uses the private value generated during keyAgreePhase1() and the len bytes of correspondentPublicValue, beginning at inOffset.

The return value is the length of the shared secret, which is the number of bytes placed in the output buffer. Places the shared secret into the given byte array.

Parameters:
correspondentPublicValue - The other party's public value.
inOffset - The offset into correspondentPublicValue where the value actually begins.
len - The length of the other party's public value.
sharedSecret - The buffer where the computed shared secret is placed.
outOffset - The offset into sharedSecret where the writing begins.
Returns:
The number of bytes actually placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.

generateSharedSecret

public byte[] generateSharedSecret()
                            throws JSAFE_InvalidUseException
Computes the shared secret and returns it in a new byte array. This method uses the private value generated during generateMyPublicValue() and the correspondent's public value extracted from the public key passed in during keyAgreeInit().

Returns:
A new byte array containing the shared secret.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.

generateSharedSecret

public abstract int generateSharedSecret(byte[] sharedSecret,
                                         int offset)
                                  throws JSAFE_InvalidUseException
Computes the shared secret and places it in the byte array sharedSecret beginning at offset. The return value is the length of the shared secret, which is the number of bytes placed in the output buffer. This method uses the private value generated during generateMyPublicValue() and the correspondent's public value extracted from the public key passed in during keyAgreeInit(). This is equivalent to phase 2 when performing classical key agreement. This method should be called after generateMyPublicValue().

Parameters:
sharedSecret - The buffer where the computed shared secret is placed.
offset - The offset into sharedSecret where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not yet initialized.

generateSharedSecret

public byte[] generateSharedSecret(JSAFE_PublicKey correspondentKey)
                            throws JSAFE_InvalidUseException,
                                   JSAFE_InvalidKeyException
Computes the shared secret and returns it in a new byte array. This method uses the private value extracted from myKey during keyAgreeInit() and the correspondent's public value extracted from correspondentKey. This is equivalent to phase 2 when performing classical key agreement. This method should be used when responding to another party's initiation. Call this method after calling keyAgreeInit(). This method returns the shared secret in a new byte array.

Parameters:
correspondentKey - The other party's public value in the form of a public key.
Returns:
A new byte array containing the shared secret.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.
JSAFE_InvalidKeyException - If the key object does not match the information loaded at initialization.

generateSharedSecret

public abstract int generateSharedSecret(JSAFE_PublicKey correspondentKey,
                                         byte[] sharedSecret,
                                         int offset)
                                  throws JSAFE_InvalidUseException,
                                         JSAFE_InvalidKeyException
Computes the shared secret and places it in the byte array sharedSecret, beginning at offset. This method uses the private value extracted from myKey during keyAgreeInit(), and the correspondent's public value that is extracted from correspondentKey. The return value is the length of the shared secret, which is the number of bytes placed in the output buffer. This is equivalent to phase 2 when performing classical key agreement. Use this method when responding to another party's initiation. Call this method after calling keyAgreeInit().

Parameters:
correspondentKey - The other party's public value in the form of a public key.
sharedSecret - The buffer where the computed shared secret is placed.
offset - The offset into sharedSecret where the writing begins.
Returns:
The number of bytes actually placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the object is not initialized.
JSAFE_InvalidKeyException - If the key object does not match the information loaded at initialization.

getPrivateValue

public byte[] getPrivateValue()
                       throws JSAFE_InvalidUseException
Retrieves the private value in a new byte array. Returns the private value computed in keyAgreePhase1 in a new byte array.

Returns:
A byte array containing the private value.
Throws:
JSAFE_InvalidUseException - If the private value is not generated.

getPrivateValue

public abstract int getPrivateValue(byte[] privateValue,
                                    int offset)
                             throws JSAFE_InvalidUseException
Retrieves the private value. Places into privateValue (beginning at offset) the private value that is computed in keyAgreePhase1(). This method returns the length of the private value, which is the number of bytes placed in the output buffer.

Parameters:
privateValue - The buffer where the generated private value is placed.
offset - The offset into privateValue where the writing begins.
Returns:
The number of bytes placed into the output buffer.
Throws:
JSAFE_InvalidUseException - If the private value is not generated.

getPrivateValueAsKey

public abstract JSAFE_PrivateKey getPrivateValueAsKey()
                                               throws JSAFE_InvalidUseException
Returns a new JSAFE_PrivateKey object that contains the private value computed in generateMyPublicValue(). Retrieves the private value in the form of a private key.

Returns:
The private value as a JSAFE_PrivateKey object (including the system parameters).
Throws:
JSAFE_InvalidUseException - If the private value is not generated.

clearSensitiveData

public void clearSensitiveData()
This method clears sensitive data from an object. Although the finalizer clears the data, there is no guarantee the garbage collector will quickly call the finalizer. This method allows a user to clear data as soon as possible. After calling clearSensitiveData(), an Init (not a ReInit) method must be called to perform other operations with the object.



RSA BSAFE Crypto-J 3.5.2