RSAKeyImpl



com.licel.jcardsim.crypto
Class RSAKeyImpl

java.lang.Object
  extended by com.licel.jcardsim.crypto.KeyImpl
      extended by com.licel.jcardsim.crypto.RSAKeyImpl
All Implemented Interfaces:
KeyWithParameters, Key, PrivateKey, PublicKey, RSAPrivateKey, RSAPublicKey
Direct Known Subclasses:
RSAPrivateCrtKeyImpl

public class RSAKeyImpl
extends KeyImpl
implements RSAPrivateKey, RSAPublicKey

Implementation RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI

See Also:
RSAPrivateKey, RSAPublicKey, RSAKeyParameters

Field Summary
protected  ByteContainer exponent
           
protected  boolean isPrivate
           
protected  ByteContainer modulus
           
 
Fields inherited from class com.licel.jcardsim.crypto.KeyImpl
size, type
 
Constructor Summary
RSAKeyImpl(boolean isPrivate, short size)
          Construct not-initialized rsa key
RSAKeyImpl(org.bouncycastle.crypto.params.RSAKeyParameters params)
          Construct and initialize rsa key with RSAKeyParameters.
 
Method Summary
 void clearKey()
          Clears the key and sets its initialized state to false.
 short getExponent(byte[] buffer, short offset)
          Returns the private exponent value of the key in plain text.
 org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
          Get RSAKeyGenerationParameters
 short getModulus(byte[] buffer, short offset)
          Returns the modulus value of the key in plain text.
 org.bouncycastle.crypto.CipherParameters getParameters()
          Get RSAKeyParameters
 boolean isInitialized()
          Reports the initialized state of the key.
 void setExponent(byte[] buffer, short offset, short length)
          Sets the private exponent value of the key.
 void setModulus(byte[] buffer, short offset, short length)
          Sets the modulus value of the key.
 
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

exponent

protected ByteContainer exponent

modulus

protected ByteContainer modulus

isPrivate

protected boolean isPrivate
Constructor Detail

RSAKeyImpl

public RSAKeyImpl(boolean isPrivate,
                  short size)
Construct not-initialized rsa key

Parameters:
isPrivate - true if private key
size - key size it bits (modulus size)
See Also:
KeyBuilder

RSAKeyImpl

public RSAKeyImpl(org.bouncycastle.crypto.params.RSAKeyParameters params)
Construct and initialize rsa key with RSAKeyParameters. Use in KeyPairImpl

Parameters:
params - key params from BouncyCastle API
See Also:
KeyPair, RSAKeyParameters
Method Detail

getExponent

public short getExponent(byte[] buffer,
                         short offset)
Description copied from interface: RSAPrivateKey
Returns the private exponent value of the key in plain text. The data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte).

Specified by:
getExponent in interface RSAPrivateKey
Specified by:
getExponent in interface RSAPublicKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the modulus value starts
Returns:
with the following reason code:
  • CryptoException.UNINITIALIZED_KEY if the private exponent value of the key has not been successfully initialized since the time the initialized state of the key was set to false.
See Also:
Key

getModulus

public short getModulus(byte[] buffer,
                        short offset)
Description copied from interface: RSAPrivateKey
Returns the modulus value of the key in plain text. The data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte).

Specified by:
getModulus in interface RSAPrivateKey
Specified by:
getModulus in interface RSAPublicKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the modulus value starts
Returns:
the byte length of the modulus value returned
See Also:
Key

setExponent

public void setExponent(byte[] buffer,
                        short offset,
                        short length)
                 throws CryptoException
Description copied from interface: RSAPrivateKey
Sets the private exponent value of the key. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input exponent data is copied into the internal representation.

Note:

  • If the key object implements the javacardx.crypto.KeyEncryption interface and the Cipher object specified via setKeyCipher() is not null, the exponent value is decrypted using the Cipher object.

Specified by:
setExponent in interface RSAPrivateKey
Specified by:
setExponent in interface RSAPublicKey
Parameters:
buffer - the input buffer
offset - the offset into the input buffer at which the modulus value begins
length - the length of the modulus
Throws:
CryptoException - with the following reason code:
  • CryptoException.ILLEGAL_VALUE if the input exponent data length is inconsistent with the implementation or if input data decryption is required and fails.

setModulus

public void setModulus(byte[] buffer,
                       short offset,
                       short length)
                throws CryptoException
Description copied from interface: RSAPrivateKey
Sets the modulus value of the key. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input modulus data is copied into the internal representation.

Note:

  • If the key object implements the javacardx.crypto.KeyEncryption interface and the Cipher object specified via setKeyCipher() is not null, the modulus value is decrypted using the Cipher object.

Specified by:
setModulus in interface RSAPrivateKey
Specified by:
setModulus in interface RSAPublicKey
Parameters:
buffer - the input buffer
offset - the offset into the input buffer at which the modulus value begins
length - the length of the modulus
Throws:
CryptoException - with the following reason code:
  • CryptoException.ILLEGAL_VALUE if the input modulus data length is inconsistent with the implementation or if input data decryption is required and fails.

clearKey

public void clearKey()
Description copied from interface: Key
Clears the key and sets its initialized state to false.

Specified by:
clearKey in interface Key

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

getParameters

public org.bouncycastle.crypto.CipherParameters getParameters()
Get RSAKeyParameters

Specified by:
getParameters in interface KeyWithParameters
Returns:
parameters for use with BouncyCastle API
See Also:
RSAKeyParameters

getKeyGenerationParameters

public org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
Get RSAKeyGenerationParameters

Specified by:
getKeyGenerationParameters in interface KeyWithParameters
Parameters:
rnd - Secure Random Generator
Returns:
parameters for use with BouncyCastle API