|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javacardx.crypto.Cipher com.licel.jcardsim.crypto.SymmetricCipherImpl
public class SymmetricCipherImpl
Implementation Cipher
with symmetric keys based
on BouncyCastle CryptoAPI
Cipher
Field Summary |
---|
Constructor Summary | |
---|---|
SymmetricCipherImpl(byte algorithm)
|
Method Summary | |
---|---|
short |
doFinal(byte[] inBuff,
short inOffset,
short inLength,
byte[] outBuff,
short outOffset)
Generates encrypted/decrypted output from all/last input data. |
byte |
getAlgorithm()
Gets the Cipher algorithm. |
void |
init(Key theKey,
byte theMode)
Initializes the Cipher object with the appropriate Key . |
void |
init(Key theKey,
byte theMode,
byte[] bArray,
short bOff,
short bLen)
Initializes the Cipher object with the appropriate Key and algorithm specific
parameters. |
short |
update(byte[] inBuff,
short inOffset,
short inLength,
byte[] outBuff,
short outOffset)
Generates encrypted/decrypted output from input data. |
Methods inherited from class javacardx.crypto.Cipher |
---|
getInstance |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SymmetricCipherImpl(byte algorithm)
Method Detail |
---|
public void init(Key theKey, byte theMode) throws CryptoException
Cipher
Cipher
object with the appropriate Key
.
This method should be used
for algorithms which do not need initialization parameters or use default parameter
values.
init()
must be used to update the Cipher
object with a new key.
If the Key
object is modified after invoking the init()
method,
the behavior of the update()
and doFinal()
methods is unspecified.
Note:
theKey
- the key object to use for encrypting or decryptingtheMode
- one of MODE_DECRYPT
or MODE_ENCRYPT
CryptoException
- with the following reason codes:
CryptoException.ILLEGAL_VALUE
if theMode
option is an undefined value or
if the Key
is inconsistent with the Cipher
implementation.
CryptoException.UNINITIALIZED_KEY
if theKey
instance is uninitialized.
public void init(Key theKey, byte theMode, byte[] bArray, short bOff, short bLen) throws CryptoException
Cipher
Cipher
object with the appropriate Key and algorithm specific
parameters.
init()
must be used to update the Cipher
object with a new key.
If the Key
object is modified after invoking the init()
method,
the behavior of the update()
and doFinal()
methods is unspecified.
Note:
bArray
.
bArray
.
CryptoException.ILLEGAL_VALUE
.
theKey
- the key object to use for encrypting or decrypting.theMode
- one of MODE_DECRYPT
or MODE_ENCRYPT
bArray
- byte array containing algorithm specific initialization infobOff
- offset within bArray where the algorithm specific data beginsbLen
- byte length of algorithm specific parameter data
CryptoException
- with the following reason codes:
CryptoException.ILLEGAL_VALUE
if theMode
option is an undefined value
or if a byte array parameter option is not supported by the algorithm or if
the bLen
is an incorrect byte length for the algorithm specific data or
if the Key
is inconsistent with the Cipher
implementation.
CryptoException.UNINITIALIZED_KEY
if theKey
instance is uninitialized.
public byte getAlgorithm()
Cipher
getAlgorithm
in class Cipher
public short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws CryptoException
Cipher
update()
method as well as input data supplied in the
inBuff
parameter.
A call to this method also resets this Cipher
object to the state it was in
when previously initialized via a call to init()
.
That is, the object is reset and available to encrypt or decrypt
(depending on the operation mode that was specified in the call to init()
) more data.
In addition, note that the initial vector(IV) used in AES and DES algorithms will be reset to 0.
Notes:
inBuff
and the output buffer,
outBuff
are the same array, then the output data area must not partially overlap the input data area such that
the input data is modified before it is used;
if inBuff==outBuff
andinOffset < outOffset < inOffset+inLength
,
incorrect output may result.
inBuff==outBuff
andoutOffset < inOffset+inLength
,
incorrect output may result.
init(Key, byte, byte[], short, short)
method.
outBuff
.
outBuff
may be larger or smaller than inLength
or even 0.
ArrayIndexOutOfBoundException
,
outBuff
may be partially modified.
inBuff
- the input buffer of data to be encrypted/decryptedinOffset
- the offset into the input buffer at which to begin encryption/decryptioninLength
- the byte length to be encrypted/decryptedoutBuff
- the output buffer, may be the same as the input bufferoutOffset
- the offset into the output buffer where the resulting output data begins
outBuff
CryptoException
- with the following reason codes:
CryptoException.UNINITIALIZED_KEY
if key not initialized.
CryptoException.INVALID_INIT
if this Cipher
object is
not initialized.
CryptoException.ILLEGAL_USE
if one of the following conditions is met:
Cipher
algorithm
does not pad the message and the message is not block aligned.
Cipher
algorithm
does not pad the message and no input
data has been provided in inBuff
or via the update()
method.
public short update(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws CryptoException
Cipher
This method requires temporary storage of intermediate results. In addition, if the input data length is not block aligned (multiple of block size) then additional internal storage may be allocated at this time to store a partial input data block. This may result in additional resource consumption and/or slow performance.
This method should only be used if all the input data required for the cipher
is not available in one byte array. If all the input data required for the cipher
is located in a single byte array, use of the doFinal()
method to
process all of the input data is recommended. The doFinal()
method
must be invoked to complete processing of any remaining input data buffered by one or more calls
to the update()
method.
Notes:
inBuff
and the output buffer,
outBuff
are the same array, then the output data area must not partially overlap the input data area such that
the input data is modified before it is used;
if inBuff==outBuff
andinOffset < outOffset < inOffset+inLength
,
incorrect output may result.
inBuff==outBuff
andoutOffset < inOffset+inLength
,
incorrect output may result.
outBuff
.
outBuff
be larger or smaller than
inLength
or even 0.
inLength
is 0 this method does nothing.
inBuff
- the input buffer of data to be encrypted/decryptedinOffset
- the offset into the input buffer at which to begin encryption/decryptioninLength
- the byte length to be encrypted/decryptedvoutBuff
- the output buffer, may be the same as the input bufferoutOffset
- the offset into the output buffer where the resulting ciphertext/plaintext begins
outBuff
CryptoException
- with the following reason codes:
CryptoException.UNINITIALIZED_KEY
if key not initialized.
CryptoException.INVALID_INIT
if this Cipher
object is
not initialized.
CryptoException.ILLEGAL_USE
if the input message length is not supported.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |