KeyAgreementImpl



com.licel.jcardsim.crypto
Class KeyAgreementImpl

java.lang.Object
  extended by javacard.security.KeyAgreement
      extended by com.licel.jcardsim.crypto.KeyAgreementImpl

public class KeyAgreementImpl
extends KeyAgreement

Implementation KeyAgreement based on BouncyCastle CryptoAPI

See Also:
KeyAgreement, ECDHBasicAgreement, ECHDCBasicAgreement

Field Summary
 
Fields inherited from class javacard.security.KeyAgreement
ALG_EC_SVDP_DH, ALG_EC_SVDP_DHC
 
Constructor Summary
KeyAgreementImpl(byte algorithm)
           
 
Method Summary
 short generateSecret(byte[] publicData, short publicOffset, short publicLength, byte[] secret, short secretOffset)
          Generates the secret data as per the requested algorithm using the PrivateKey specified during initialization and the public key data provided.
 byte getAlgorithm()
          Gets the KeyAgreement algorithm.
 void init(PrivateKey privateKey)
          Initializes the object with the given private key.
 
Methods inherited from class javacard.security.KeyAgreement
getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyAgreementImpl

public KeyAgreementImpl(byte algorithm)
Method Detail

init

public void init(PrivateKey privateKey)
          throws CryptoException
Description copied from class: KeyAgreement
Initializes the object with the given private key.

Specified by:
init in class KeyAgreement
Parameters:
privateKey - the private key
Throws:
CryptoException - with the following reason codes:
  • CryptoException.ILLEGAL_VALUE if the input key type is inconsistent with the KeyAgreement algorithm, for example, if the KeyAgreement algorithm is ALG_EC_SVDP_DH and the key type is TYPE_RSA_PRIVATE, or if privKey is inconsistent with the implementation.
  • CryptoException.UNINITIALIZED_KEY if privKey is uninitialized, or if the KeyAgreement algorithm is set to ALG_EC_SVDP_DHC and the cofactor, K, has not been successfully initialized since the time the initialized state of the key was set to false.

getAlgorithm

public byte getAlgorithm()
Description copied from class: KeyAgreement
Gets the KeyAgreement algorithm.

Specified by:
getAlgorithm in class KeyAgreement
Returns:
the algorithm code defined above

generateSecret

public short generateSecret(byte[] publicData,
                            short publicOffset,
                            short publicLength,
                            byte[] secret,
                            short secretOffset)
                     throws CryptoException
Description copied from class: KeyAgreement
Generates the secret data as per the requested algorithm using the PrivateKey specified during initialization and the public key data provided. Note that in the case of the algorithms ALG_EC_SVDP_DH and ALG_EC_SVDP_DHC the public key data provided should be the public elliptic curve point of the second party in the protocol, specified as per ANSI X9.62. A specific implementation need not support the compressed form, but must support the uncompressed form of the point.

Specified by:
generateSecret in class KeyAgreement
Parameters:
publicData - buffer holding the public data of the second party
publicOffset - offset into the publicData buffer at which the data begins
publicLength - byte length of the public data
secret - buffer to hold the secret output
secretOffset - offset into the secret array at which to start writing the secret
Returns:
byte length of the secret
Throws:
CryptoException - with the following reason codes:
  • CryptoException.ILLEGAL_VALUE if the publicData data format is incorrect, or if the publicData data is inconsistent with the PrivateKey specified during initialization.
  • CryptoException.INVALID_INIT if this KeyAgreement object is not initialized.