public abstract class CipherSpiExt
extends javax.crypto.CipherSpi
Modifier and Type | Field and Description |
---|---|
static int |
DECRYPT_MODE
Constant specifying decrypt mode.
|
static int |
ENCRYPT_MODE
Constant specifying encrypt mode.
|
protected int |
opMode
The operation mode for this cipher (
ENCRYPT_MODE or
DECRYPT_MODE ). |
Constructor and Description |
---|
CipherSpiExt() |
Modifier and Type | Method and Description |
---|---|
byte[] |
doFinal()
Finish a multiple-part encryption or decryption operation (depending on
how this cipher was initialized).
|
byte[] |
doFinal(byte[] input)
Finish a multiple-part encryption or decryption operation (depending on
how this cipher was initialized).
|
abstract byte[] |
doFinal(byte[] input,
int inOff,
int inLen)
Finish a multiple-part encryption or decryption operation (depending on
how this cipher was initialized).
|
abstract int |
doFinal(byte[] input,
int inOff,
int inLen,
byte[] output,
int outOff)
Finish a multiple-part encryption or decryption operation (depending on
how this cipher was initialized).
|
protected byte[] |
engineDoFinal(byte[] input,
int inOff,
int inLen)
Return the result of the last step of a multi-step en-/decryption
operation or the result of a single-step en-/decryption operation by
processing the given input data and any remaining buffered data.
|
protected int |
engineDoFinal(byte[] input,
int inOff,
int inLen,
byte[] output,
int outOff)
Perform the last step of a multi-step en-/decryption operation or a
single-step en-/decryption operation by processing the given input data
and any remaining buffered data.
|
protected int |
engineGetBlockSize() |
protected byte[] |
engineGetIV()
Return the initialization vector.
|
protected int |
engineGetKeySize(java.security.Key key)
Return the key size of the given key object in bits.
|
protected int |
engineGetOutputSize(int inLen)
Return the length in bytes that an output buffer would need to be in
order to hold the result of the next update or doFinal operation, given
the input length inputLen (in bytes).
|
protected java.security.AlgorithmParameters |
engineGetParameters()
Returns the parameters used with this cipher.
|
protected void |
engineInit(int opMode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom javaRand)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness.
|
protected void |
engineInit(int opMode,
java.security.Key key,
java.security.AlgorithmParameters algParams,
java.security.SecureRandom random)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness.
|
protected void |
engineInit(int opMode,
java.security.Key key,
java.security.SecureRandom random)
Initialize this cipher object with a proper key and some random seed.
|
protected void |
engineSetMode(java.lang.String modeName)
Set the mode of this cipher.
|
protected void |
engineSetPadding(java.lang.String paddingName)
Set the padding scheme of this cipher.
|
protected byte[] |
engineUpdate(byte[] input,
int inOff,
int inLen)
Return the result of the next step of a multi-step en-/decryption
operation.
|
protected int |
engineUpdate(byte[] input,
int inOff,
int inLen,
byte[] output,
int outOff)
Perform the next step of a multi-step en-/decryption operation.
|
abstract int |
getBlockSize() |
abstract byte[] |
getIV()
Return the initialization vector.
|
abstract int |
getKeySize(java.security.Key key)
Return the key size of the given key object in bits.
|
abstract java.lang.String |
getName() |
abstract int |
getOutputSize(int inputLen)
Returns the length in bytes that an output buffer would need to be in
order to hold the result of the next update or doFinal operation, given
the input length inputLen (in bytes).
|
abstract java.security.spec.AlgorithmParameterSpec |
getParameters()
Returns the parameters used with this cipher.
|
abstract void |
initDecrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec cipherParams)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness for decryption.
|
abstract void |
initEncrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec cipherParams,
java.security.SecureRandom random)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness for encryption.
|
protected abstract void |
setMode(java.lang.String mode)
Set the mode of this cipher.
|
protected abstract void |
setPadding(java.lang.String padding)
Set the padding mechanism of this cipher.
|
byte[] |
update(byte[] input)
Continue a multiple-part encryption or decryption operation (depending on
how this cipher was initialized), processing another data part.
|
abstract byte[] |
update(byte[] input,
int inOff,
int inLen)
Continue a multiple-part encryption or decryption operation (depending on
how this cipher was initialized), processing another data part.
|
abstract int |
update(byte[] input,
int inOff,
int inLen,
byte[] output,
int outOff)
Continue a multiple-part encryption or decryption operation (depending on
how this cipher was initialized), processing another data part.
|
public static final int ENCRYPT_MODE
public static final int DECRYPT_MODE
protected int opMode
ENCRYPT_MODE
or
DECRYPT_MODE
).protected final void engineInit(int opMode, java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
If this cipher (including its underlying mode or padding scheme) requires any random bytes, it will obtain them from random.
Note: If the mode needs an initialization vector, a blank array is used in this case.
engineInit
in class javax.crypto.CipherSpi
opMode
- the operation mode (ENCRYPT_MODE
or
DECRYPT_MODE
)key
- the keyrandom
- the random seedjava.security.InvalidKeyException
- if the key is inappropriate for initializing this cipher.protected final void engineInit(int opMode, java.security.Key key, java.security.AlgorithmParameters algParams, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If this cipher (including its underlying mode or padding scheme) requires any random bytes, it will obtain them from random. Note that when a cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.
Note: If the mode needs an initialization vector, a try to retrieve it from the AlgorithmParametersSpec is made.
engineInit
in class javax.crypto.CipherSpi
opMode
- the operation mode (ENCRYPT_MODE
or
DECRYPT_MODE
)key
- the keyalgParams
- the algorithm parametersrandom
- the random seedjava.security.InvalidKeyException
- if the key is inappropriate for initializing this block
cipher.java.security.InvalidAlgorithmParameterException
- if the parameters are inappropriate for initializing this
block cipher.protected void engineInit(int opMode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom javaRand) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
engineInit
in class javax.crypto.CipherSpi
opMode
- the operation mode (ENCRYPT_MODE
or
DECRYPT_MODE
)key
- the encryption keyparams
- the algorithm parametersjavaRand
- the source of randomnessjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipherjava.security.InvalidAlgorithmParameterException
- if the given algorithm parameters are inappropriate for
this cipher, or if this cipher is being initialized for
decryption and requires algorithm parameters and the
parameters are null.protected final byte[] engineDoFinal(byte[] input, int inOff, int inLen) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
engineDoFinal
in class javax.crypto.CipherSpi
input
- the byte array holding the data to be processedinOff
- the offset indicating the start position within the input
byte arrayinLen
- the number of bytes to be processedjavax.crypto.IllegalBlockSizeException
- if the ciphertext length is not a multiple of the
blocklength.javax.crypto.BadPaddingException
- if unpadding is not possible.protected final int engineDoFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
engineDoFinal
in class javax.crypto.CipherSpi
input
- the byte array holding the data to be processedinOff
- the offset indicating the start position within the input
byte arrayinLen
- the number of bytes to be processedoutput
- the byte array for holding the resultoutOff
- the offset indicating the start position within the output
byte array to which the en/decrypted data is writtenjavax.crypto.ShortBufferException
- if the output buffer is too short to hold the output.javax.crypto.IllegalBlockSizeException
- if the ciphertext length is not a multiple of the
blocklength.javax.crypto.BadPaddingException
- if unpadding is not possible.protected final int engineGetBlockSize()
engineGetBlockSize
in class javax.crypto.CipherSpi
protected final int engineGetKeySize(java.security.Key key) throws java.security.InvalidKeyException
engineGetKeySize
in class javax.crypto.CipherSpi
key
- the key objectjava.security.InvalidKeyException
- if key is invalid.protected final byte[] engineGetIV()
engineGetIV
in class javax.crypto.CipherSpi
protected final int engineGetOutputSize(int inLen)
This call takes into account any unprocessed (buffered) data from a previous update call, and padding.
The actual output length of the next update or doFinal call may be smaller than the length returned by this method.
engineGetOutputSize
in class javax.crypto.CipherSpi
inLen
- the input length (in bytes)protected final java.security.AlgorithmParameters engineGetParameters()
The returned parameters may be the same that were used to initialize this cipher, or may contain the default set of parameters or a set of randomly generated parameters used by the underlying cipher implementation (provided that the underlying cipher implementation uses a default set of parameters or creates new parameters if it needs parameters but was not initialized with any).
engineGetParameters
in class javax.crypto.CipherSpi
protected final void engineSetMode(java.lang.String modeName) throws java.security.NoSuchAlgorithmException
engineSetMode
in class javax.crypto.CipherSpi
modeName
- the cipher modejava.security.NoSuchAlgorithmException
- if neither the mode with the given name nor the default
mode can be foundprotected final void engineSetPadding(java.lang.String paddingName) throws javax.crypto.NoSuchPaddingException
engineSetPadding
in class javax.crypto.CipherSpi
paddingName
- the padding schemejavax.crypto.NoSuchPaddingException
- if the requested padding scheme cannot be found.protected final byte[] engineUpdate(byte[] input, int inOff, int inLen)
engineUpdate
in class javax.crypto.CipherSpi
input
- the byte array holding the data to be processedinOff
- the offset indicating the start position within the input
byte arrayinLen
- the number of bytes to be processedprotected final int engineUpdate(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException
engineUpdate
in class javax.crypto.CipherSpi
input
- the byte array holding the data to be processedinOff
- the offset indicating the start position within the input
byte arrayinLen
- the number of bytes to be processedoutput
- the byte array for holding the resultoutOff
- the offset indicating the start position within the output
byte array to which the en-/decrypted data is writtenjavax.crypto.ShortBufferException
- if the output buffer is too short to hold the output.public abstract void initEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec cipherParams, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If this cipher requires any algorithm parameters and paramSpec is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).
If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.
Note that when a cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.
key
- the encryption keycipherParams
- the cipher parametersrandom
- the source of randomnessjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
block cipher.java.security.InvalidAlgorithmParameterException
- if the parameters are inappropriate for initializing this
block cipher.public abstract void initDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec cipherParams) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If this cipher requires any algorithm parameters and paramSpec is null,
the underlying cipher implementation is supposed to generate the required
parameters itself (using provider-specific default or random values) if
it is being initialized for encryption, and throw an
InvalidAlgorithmParameterException
if it is being initialized for
decryption. The generated parameters can be retrieved using
engineGetParameters or engineGetIV (if the parameter is an IV).
If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.
Note that when a cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.
key
- the encryption keycipherParams
- the cipher parametersjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
block cipher.java.security.InvalidAlgorithmParameterException
- if the parameters are inappropriate for initializing this
block cipher.public abstract java.lang.String getName()
public abstract int getBlockSize()
public abstract int getOutputSize(int inputLen)
This call takes into account any unprocessed (buffered) data from a previous update call, and padding.
The actual output length of the next update or doFinal call may be smaller than the length returned by this method.
inputLen
- the input length (in bytes)public abstract int getKeySize(java.security.Key key) throws java.security.InvalidKeyException
key
- the key objectjava.security.InvalidKeyException
- if key is invalid.public abstract java.security.spec.AlgorithmParameterSpec getParameters()
The returned parameters may be the same that were used to initialize this cipher, or may contain the default set of parameters or a set of randomly generated parameters used by the underlying cipher implementation (provided that the underlying cipher implementation uses a default set of parameters or creates new parameters if it needs parameters but was not initialized with any).
public abstract byte[] getIV()
protected abstract void setMode(java.lang.String mode) throws java.security.NoSuchAlgorithmException
mode
- the cipher modejava.security.NoSuchAlgorithmException
- if the requested mode cannot be found.protected abstract void setPadding(java.lang.String padding) throws javax.crypto.NoSuchPaddingException
padding
- the padding mechanismjavax.crypto.NoSuchPaddingException
- if the requested padding scheme cannot be found.public final byte[] update(byte[] input)
input
- the input bufferpublic abstract byte[] update(byte[] input, int inOff, int inLen)
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthpublic abstract int update(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthoutput
- the output bufferoutOff
- the offset where the result is storedjavax.crypto.ShortBufferException
- if the output buffer is too small to hold the result.public final byte[] doFinal() throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
javax.crypto.IllegalBlockSizeException
- if this cipher is a block cipher and the total input
length is not a multiple of the block size (for
encryption when no padding is used or for decryption).javax.crypto.BadPaddingException
- if this cipher is a block cipher and unpadding fails.public final byte[] doFinal(byte[] input) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
input
- the input bufferjavax.crypto.IllegalBlockSizeException
- if this cipher is a block cipher and the total input
length is not a multiple of the block size (for
encryption when no padding is used or for decryption).javax.crypto.BadPaddingException
- if this cipher is a block cipher and unpadding fails.public abstract byte[] doFinal(byte[] input, int inOff, int inLen) throws javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthjavax.crypto.IllegalBlockSizeException
- if this cipher is a block cipher and the total input
length is not a multiple of the block size (for
encryption when no padding is used or for decryption).javax.crypto.BadPaddingException
- if this cipher is a block cipher and unpadding fails.public abstract int doFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthoutput
- the buffer for the resultoutOff
- the offset where the result is storedjavax.crypto.ShortBufferException
- if the output buffer is too small to hold the result.javax.crypto.IllegalBlockSizeException
- if this cipher is a block cipher and the total input
length is not a multiple of the block size (for
encryption when no padding is used or for decryption).javax.crypto.BadPaddingException
- if this cipher is a block cipher and unpadding fails.