public abstract class Cipher
extends java.lang.Object
If you get a totalcross.crypto.CryptoException: Illegal key size
, you must download the strong cryptography files from Oracle
site. In order to do that, go to the ReadMe file whole link is below the download link. In this file, search for "Unlimited Strength Java
Cryptography Extension" and follow the instructions.
Modifier and Type | Field and Description |
---|---|
protected int |
chaining |
static int |
CHAINING_CBC
Constant used to initialize cipher using CBC chaining.
|
static int |
CHAINING_ECB
Constant used to initialize cipher using ECB chaining.
|
static int |
CHAINING_NONE
Constant used to initialize cipher using no chaining.
|
protected byte[] |
iv |
protected Key |
key |
protected java.lang.Object |
nativeHeap |
protected int |
operation |
static int |
OPERATION_DECRYPT
Constant used to initialize cipher to decrypt.
|
static int |
OPERATION_ENCRYPT
Constant used to initialize cipher to encrypt.
|
protected int |
padding |
static int |
PADDING_NONE
Constant used to initialize cipher using no padding.
|
static int |
PADDING_PKCS1
Constant used to initialize cipher using PKCS #1 padding.
|
static int |
PADDING_PKCS5
Constant used to initialize cipher using PKCS #5 padding.
Comment about PKCS#5 padding: PKCS#5 padding is a padding scheme that always adds padding bytes even if the input size is a multiple of the block size (i. |
Constructor and Description |
---|
Cipher() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
doReset() |
abstract java.lang.String |
getAlgorithm()
Returns the name of the algorithm.
|
abstract int |
getBlockLength()
Returns the block length.
|
byte[] |
getIV()
Returns the initialization vector (IV) in a new buffer.
|
byte[] |
getOutput()
Finalizes the encryption or decryption operation (depending on how this cipher was initialized) by processing all the accumulated input data
and returning the result in a new buffer.
|
protected abstract boolean |
isChainingSupported(int chaining) |
protected abstract boolean |
isKeySupported(Key key,
int operation) |
protected abstract boolean |
isPaddingSupported(int padding) |
protected abstract byte[] |
process(byte[] data) |
void |
reset(int operation,
Key key)
Initializes this cipher in encryption or decryption mode, without chaining or padding.
|
void |
reset(int operation,
Key key,
int chaining)
Initializes this cipher in encryption or decryption mode, with the given chaining mode and without a padding.
|
void |
reset(int operation,
Key key,
int chaining,
byte[] iv)
Initializes this cipher in encryption or decryption mode, with the given chaining mode, initialization vector and without a padding.
|
void |
reset(int operation,
Key key,
int chaining,
byte[] iv,
int padding)
Initializes this cipher in encryption or decryption mode, with the given chaining
mode, initialization vector padding.
|
java.lang.String |
toString()
Returns the name of the algorithm.
|
void |
update(byte[] data)
Updates the input data that will be processed by this cipher algorithm.
|
void |
update(byte[] data,
int start,
int count)
Updates the input data that will be processed by this cipher algorithm.
|
void |
update(int data)
Updates the input data that will be processed by this cipher algorithm.
|
protected int operation
protected Key key
protected int chaining
protected byte[] iv
protected int padding
protected java.lang.Object nativeHeap
public static final int OPERATION_ENCRYPT
public static final int OPERATION_DECRYPT
public static final int CHAINING_NONE
public static final int CHAINING_ECB
public static final int CHAINING_CBC
public static final int PADDING_NONE
public static final int PADDING_PKCS1
public static final int PADDING_PKCS5
public final java.lang.String toString()
toString
in class java.lang.Object
public final byte[] getIV()
null
if the underlying algorithm does not use an IV, or if the IV has not
been set yet.public final void reset(int operation, Key key) throws CryptoException
operation
- The operation mode of this cipher (OPERATION_ENCRYPT
or OPERATION_DECRYPT
).key
- The key.CryptoException
- If one or more initialization parameters are invalid or the cipher fails to initialize with the given parameters.public final void reset(int operation, Key key, int chaining) throws CryptoException
operation
- The operation mode of this cipher (OPERATION_ENCRYPT
or OPERATION_DECRYPT
).key
- The key.chaining
- The chaining mode of this cipher (CHAINING_NONE
, CHAINING_ECB
, or
CHAINING_CBC
).CryptoException
- If one or more initialization parameters are invalid or the cipher fails to initialize with the given parameters.public final void reset(int operation, Key key, int chaining, byte[] iv) throws CryptoException
operation
- The operation mode of this cipher (OPERATION_ENCRYPT
or OPERATION_DECRYPT
).key
- The key.chaining
- The chaining mode of this cipher (CHAINING_NONE
, CHAINING_ECB
, or
CHAINING_CBC
).iv
- The initialization vector.CryptoException
- if one or more initialization parameters are invalid or the cipher fails to initialize with the given parameters.public final void reset(int operation, Key key, int chaining, byte[] iv, int padding) throws CryptoException
operation
- The operation mode of this cipher (OPERATION_ENCRYPT
or OPERATION_DECRYPT
).key
- The key.chaining
- The chaining mode of this cipher (CHAINING_NONE
, CHAINING_ECB
, or
CHAINING_CBC
).iv
- The initialization vector.padding
- The padding mode of this cipher (PADDING_NONE
, PADDING_PKCS1
, or PADDING_PKCS5
).CryptoException
- if one or more initialization parameters are invalid or the cipher fails to initialize with the given parameters.public final void update(int data)
getOutput()
is finally called.data
- The input data.public final void update(byte[] data)
getOutput()
is finally called.data
- The input data.public final void update(byte[] data, int start, int count)
getOutput()
is finally called.data
- The input data.start
- The offset in data
where the data starts.count
- The input length.public byte[] getOutput() throws CryptoException
CryptoException
public abstract java.lang.String getAlgorithm()
public abstract int getBlockLength()
protected abstract void doReset() throws NoSuchAlgorithmException, CryptoException
protected abstract byte[] process(byte[] data) throws CryptoException
CryptoException
protected abstract boolean isKeySupported(Key key, int operation)
protected abstract boolean isChainingSupported(int chaining)
protected abstract boolean isPaddingSupported(int padding)