SymmetricKeyImpl



com.licel.jcardsim.crypto
Class SymmetricKeyImpl

java.lang.Object
  extended by com.licel.jcardsim.crypto.KeyImpl
      extended by com.licel.jcardsim.crypto.SymmetricKeyImpl
All Implemented Interfaces:
KeyWithParameters, AESKey, DESKey, Key, SecretKey

public class SymmetricKeyImpl
extends KeyImpl
implements DESKey, AESKey

Implementation of secret key

See Also:
DESKey, AESKey

Field Summary
protected  ByteContainer key
           
 
Fields inherited from class com.licel.jcardsim.crypto.KeyImpl
size, type
 
Constructor Summary
SymmetricKeyImpl(byte keyType, short keySize)
          Create new instance of SymmetricKeyImpl
 
Method Summary
 void clearKey()
          Clears the key and sets its initialized state to false.
 org.bouncycastle.crypto.BlockCipher getCipher()
          Return the BouncyCastle BlockCipher for using with this key
 byte getKey(byte[] keyData, short kOff)
          Returns the Key data in plain text.
 org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
          Get keypair generation parameters for use with BouncyCastle Crypto API
 org.bouncycastle.crypto.CipherParameters getParameters()
          Return the BouncyCastle KeyParameter of the key
 boolean isInitialized()
          Reports the initialized state of the key.
 void setKey(byte[] keyData, short kOff)
          Sets the Key data.
 
Methods inherited from class com.licel.jcardsim.crypto.KeyImpl
getSize, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javacard.security.Key
getSize, getType
 

Field Detail

key

protected ByteContainer key
Constructor Detail

SymmetricKeyImpl

public SymmetricKeyImpl(byte keyType,
                        short keySize)
Create new instance of SymmetricKeyImpl

Parameters:
keyType - keyType interface
keySize - keySize in bits
See Also:
KeyBuilder
Method Detail

clearKey

public void clearKey()
Clears the key and sets its initialized state to false.

Specified by:
clearKey in interface Key

setKey

public void setKey(byte[] keyData,
                   short kOff)
            throws CryptoException,
                   NullPointerException,
                   ArrayIndexOutOfBoundsException
Sets the Key data.

Specified by:
setKey in interface AESKey
Specified by:
setKey in interface DESKey
Parameters:
keyData - byte array containing key initialization data
kOff - offset within keyData to start
Throws:
CryptoException - with the following reason code:
  • CryptoException.ILLEGAL_VALUE if input data decryption is required and fails.
NullPointerException - - if the keyData parameter is null
ArrayIndexOutOfBoundsException - if kOff is negative or the keyData array is too short

getKey

public byte getKey(byte[] keyData,
                   short kOff)
Returns the Key data in plain text.

Specified by:
getKey in interface AESKey
Specified by:
getKey in interface DESKey
Parameters:
keyData - byte array to return key data
kOff - offset within keyData to start
Returns:
the byte length of the key data returned
See Also:
Key

getParameters

public org.bouncycastle.crypto.CipherParameters getParameters()
                                                       throws CryptoException
Return the BouncyCastle KeyParameter of the key

Specified by:
getParameters in interface KeyWithParameters
Returns:
parameter of the key
Throws:
CryptoException - if key not initialized
See Also:
KeyParameter

getCipher

public org.bouncycastle.crypto.BlockCipher getCipher()
                                              throws CryptoException
Return the BouncyCastle BlockCipher for using with this key

Returns:
BlockCipher for this key
Throws:
CryptoException - if key not initialized
See Also:
BlockCipher

isInitialized

public boolean isInitialized()
Description copied from interface: Key
Reports the initialized state of the key. Keys must be initialized before being used.

A Key object sets its initialized state to true only when all the associated Key object parameters have been set at least once since the time the initialized state was set to false.

A newly created Key object sets its initialized state to false. Invocation of the clearKey() method sets the initialized state to false. A key with transient key data sets its initialized state to false on the associated clear events.

Specified by:
isInitialized in interface Key
Returns:
true if the key has been initialized

getKeyGenerationParameters

public org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
Description copied from interface: KeyWithParameters
Get keypair generation parameters for use with BouncyCastle Crypto API

Specified by:
getKeyGenerationParameters in interface KeyWithParameters
Returns:
key parameters