RSAPrivateCrtKeyImpl



com.licel.jcardsim.crypto
Class RSAPrivateCrtKeyImpl

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

public class RSAPrivateCrtKeyImpl
extends RSAKeyImpl
implements RSAPrivateCrtKey

Implementation RSAPrivateCrtKey based on BouncyCastle CryptoAPI

See Also:
RSAPrivateCrtKey, RSAPrivateCrtKeyParameters

Field Summary
protected  ByteContainer dp1
           
protected  ByteContainer dq1
           
protected  ByteContainer p
           
protected  ByteContainer pq
           
protected  ByteContainer publicExponent
           
protected  ByteContainer q
           
 
Fields inherited from class com.licel.jcardsim.crypto.RSAKeyImpl
exponent, isPrivate, modulus
 
Fields inherited from class com.licel.jcardsim.crypto.KeyImpl
size, type
 
Constructor Summary
RSAPrivateCrtKeyImpl(org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters params)
          Construct and initialize rsa key with RSAPrivateCrtKeyParameters.
RSAPrivateCrtKeyImpl(short keySize)
          Construct not-initialized rsa private crt key
 
Method Summary
 void clearKey()
          Clears the key and sets its initialized state to false.
 short getDP1(byte[] buffer, short offset)
          Returns the value of the DP1 parameter in plain text.
 short getDQ1(byte[] buffer, short offset)
          Returns the value of the DQ1 parameter in plain text.
 short getP(byte[] buffer, short offset)
          Returns the value of the P parameter in plain text.
 org.bouncycastle.crypto.CipherParameters getParameters()
          Get RSAKeyParameters
 short getPQ(byte[] buffer, short offset)
          Returns the value of the PQ parameter in plain text.
 short getQ(byte[] buffer, short offset)
          Returns the value of the Q parameter in plain text.
 boolean isInitialized()
          Reports the initialized state of the key.
 void setDP1(byte[] buffer, short offset, short length)
          Sets the value of the DP1 parameter.
 void setDQ1(byte[] buffer, short offset, short length)
          Sets the value of the DQ1 parameter.
 void setP(byte[] buffer, short offset, short length)
          Sets the value of the P parameter.
 void setPQ(byte[] buffer, short offset, short length)
          Sets the value of the PQ parameter.
 void setPublicExponent(byte[] buffer, short offset, short length)
           
 void setQ(byte[] buffer, short offset, short length)
          Sets the value of the Q parameter.
 
Methods inherited from class com.licel.jcardsim.crypto.RSAKeyImpl
getExponent, getKeyGenerationParameters, getModulus, setExponent, setModulus
 
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

p

protected ByteContainer p

q

protected ByteContainer q

dp1

protected ByteContainer dp1

dq1

protected ByteContainer dq1

pq

protected ByteContainer pq

publicExponent

protected ByteContainer publicExponent
Constructor Detail

RSAPrivateCrtKeyImpl

public RSAPrivateCrtKeyImpl(short keySize)
Construct not-initialized rsa private crt key

Parameters:
size - key size it bits (modulus size)
See Also:
KeyBuilder

RSAPrivateCrtKeyImpl

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

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

setPublicExponent

public void setPublicExponent(byte[] buffer,
                              short offset,
                              short length)
                       throws CryptoException
Throws:
CryptoException

setP

public void setP(byte[] buffer,
                 short offset,
                 short length)
          throws CryptoException
Description copied from interface: RSAPrivateCrtKey
Sets the value of the P parameter. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input P parameter 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 P parameter value is decrypted using the Cipher object.

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

setQ

public void setQ(byte[] buffer,
                 short offset,
                 short length)
          throws CryptoException
Description copied from interface: RSAPrivateCrtKey
Sets the value of the Q parameter. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input Q parameter 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 Q parameter value is decrypted using the Cipher object.

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

setDP1

public void setDP1(byte[] buffer,
                   short offset,
                   short length)
            throws CryptoException
Description copied from interface: RSAPrivateCrtKey
Sets the value of the DP1 parameter. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input DP1 parameter 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 DP1 parameter value is decrypted using the Cipher object.

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

setDQ1

public void setDQ1(byte[] buffer,
                   short offset,
                   short length)
            throws CryptoException
Description copied from interface: RSAPrivateCrtKey
Sets the value of the DQ1 parameter. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input DQ1 parameter 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 DQ1 parameter value is decrypted using the Cipher object.

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

setPQ

public void setPQ(byte[] buffer,
                  short offset,
                  short length)
           throws CryptoException
Description copied from interface: RSAPrivateCrtKey
Sets the value of the PQ parameter. The plain text data format is big-endian and right-aligned (the least significant bit is the least significant bit of last byte). Input PQ parameter 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 PQ parameter value is decrypted using the Cipher object.

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

getP

public short getP(byte[] buffer,
                  short offset)
Description copied from interface: RSAPrivateCrtKey
Returns the value of the P parameter 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:
getP in interface RSAPrivateCrtKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the parameter value begins
Returns:
the byte length of the P parameter value returned
See Also:
Key

getQ

public short getQ(byte[] buffer,
                  short offset)
Description copied from interface: RSAPrivateCrtKey
Returns the value of the Q parameter 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:
getQ in interface RSAPrivateCrtKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the parameter value begins
Returns:
the byte length of the Q parameter value returned
See Also:
Key

getDP1

public short getDP1(byte[] buffer,
                    short offset)
Description copied from interface: RSAPrivateCrtKey
Returns the value of the DP1 parameter 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:
getDP1 in interface RSAPrivateCrtKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the parameter value begins
Returns:
the byte length of the DP1 parameter value returned
See Also:
Key

getDQ1

public short getDQ1(byte[] buffer,
                    short offset)
Description copied from interface: RSAPrivateCrtKey
Returns the value of the DQ1 parameter 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:
getDQ1 in interface RSAPrivateCrtKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the parameter value begins
Returns:
the byte length of the DQ1 parameter value returned
See Also:
Key

getPQ

public short getPQ(byte[] buffer,
                   short offset)
Description copied from interface: RSAPrivateCrtKey
Returns the value of the PQ parameter 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:
getPQ in interface RSAPrivateCrtKey
Parameters:
buffer - the output buffer
offset - the offset into the output buffer at which the parameter value begins
Returns:
the byte length of the PQ parameter value returned
See Also:
Key

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
Overrides:
clearKey in class RSAKeyImpl

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
Overrides:
isInitialized in class RSAKeyImpl
Returns:
true if the key has been initialized

getParameters

public org.bouncycastle.crypto.CipherParameters getParameters()
Description copied from class: RSAKeyImpl
Get RSAKeyParameters

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