public abstract class CipherSpiExt extends 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(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 AlgorithmParameters |
engineGetParameters()
Returns the parameters used with this cipher.
|
protected void |
engineInit(int opMode,
Key key,
AlgorithmParameterSpec params,
SecureRandom javaRand)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness.
|
protected void |
engineInit(int opMode,
Key key,
AlgorithmParameters algParams,
SecureRandom random)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness.
|
protected void |
engineInit(int opMode,
Key key,
SecureRandom random)
Initialize this cipher object with a proper key and some random seed.
|
protected void |
engineSetMode(String modeName)
Set the mode of this cipher.
|
protected void |
engineSetPadding(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(Key key)
Return the key size of the given key object in bits.
|
abstract 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 AlgorithmParameterSpec |
getParameters()
Returns the parameters used with this cipher.
|
abstract void |
initDecrypt(Key key,
AlgorithmParameterSpec cipherParams)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness for decryption.
|
abstract void |
initEncrypt(Key key,
AlgorithmParameterSpec cipherParams,
SecureRandom random)
Initialize this cipher with a key, a set of algorithm parameters, and a
source of randomness for encryption.
|
protected abstract void |
setMode(String mode)
Set the mode of this cipher.
|
protected abstract void |
setPadding(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.
|
engineDoFinal, engineUnwrap, engineUpdate, engineUpdateAAD, engineUpdateAAD, engineWrap
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, Key key, SecureRandom random) throws 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 CipherSpi
opMode
- the operation mode (ENCRYPT_MODE
or
DECRYPT_MODE
)key
- the keyrandom
- the random seedInvalidKeyException
- if the key is inappropriate for initializing this cipher.protected final void engineInit(int opMode, Key key, AlgorithmParameters algParams, SecureRandom random) throws InvalidKeyException, 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 CipherSpi
opMode
- the operation mode (ENCRYPT_MODE
or
DECRYPT_MODE
)key
- the keyalgParams
- the algorithm parametersrandom
- the random seedInvalidKeyException
- if the key is inappropriate for initializing this block
cipher.InvalidAlgorithmParameterException
- if the parameters are inappropriate for initializing this
block cipher.protected void engineInit(int opMode, Key key, AlgorithmParameterSpec params, SecureRandom javaRand) throws InvalidKeyException, InvalidAlgorithmParameterException
engineInit
in class CipherSpi
opMode
- the operation mode (ENCRYPT_MODE
or
DECRYPT_MODE
)key
- the encryption keyparams
- the algorithm parametersjavaRand
- the source of randomnessInvalidKeyException
- if the given key is inappropriate for initializing this
cipherInvalidAlgorithmParameterException
- 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 IllegalBlockSizeException, BadPaddingException
engineDoFinal
in class 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 processedIllegalBlockSizeException
- if the ciphertext length is not a multiple of the
blocklength.BadPaddingException
- if unpadding is not possible.protected final int engineDoFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException
engineDoFinal
in class 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 writtenShortBufferException
- if the output buffer is too short to hold the output.IllegalBlockSizeException
- if the ciphertext length is not a multiple of the
blocklength.BadPaddingException
- if unpadding is not possible.protected final int engineGetBlockSize()
engineGetBlockSize
in class CipherSpi
protected final int engineGetKeySize(Key key) throws InvalidKeyException
engineGetKeySize
in class CipherSpi
key
- the key objectInvalidKeyException
- if key is invalid.protected final byte[] engineGetIV()
engineGetIV
in class 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 CipherSpi
inLen
- the input length (in bytes)protected final 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 CipherSpi
protected final void engineSetMode(String modeName) throws NoSuchAlgorithmException
engineSetMode
in class CipherSpi
modeName
- the cipher modeNoSuchAlgorithmException
- if neither the mode with the given name nor the default
mode can be foundprotected final void engineSetPadding(String paddingName) throws NoSuchPaddingException
engineSetPadding
in class CipherSpi
paddingName
- the padding schemeNoSuchPaddingException
- if the requested padding scheme cannot be found.protected final byte[] engineUpdate(byte[] input, int inOff, int inLen)
engineUpdate
in class 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 ShortBufferException
engineUpdate
in class 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 writtenShortBufferException
- if the output buffer is too short to hold the output.public abstract void initEncrypt(Key key, AlgorithmParameterSpec cipherParams, SecureRandom random) throws InvalidKeyException, 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 randomnessInvalidKeyException
- if the given key is inappropriate for initializing this
block cipher.InvalidAlgorithmParameterException
- if the parameters are inappropriate for initializing this
block cipher.public abstract void initDecrypt(Key key, AlgorithmParameterSpec cipherParams) throws InvalidKeyException, 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 parametersInvalidKeyException
- if the given key is inappropriate for initializing this
block cipher.InvalidAlgorithmParameterException
- if the parameters are inappropriate for initializing this
block cipher.public abstract 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(Key key) throws InvalidKeyException
key
- the key objectInvalidKeyException
- if key is invalid.public abstract 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(String mode) throws NoSuchAlgorithmException
mode
- the cipher modeNoSuchAlgorithmException
- if the requested mode cannot be found.protected abstract void setPadding(String padding) throws NoSuchPaddingException
padding
- the padding mechanismNoSuchPaddingException
- 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 ShortBufferException
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthoutput
- the output bufferoutOff
- the offset where the result is storedShortBufferException
- if the output buffer is too small to hold the result.public final byte[] doFinal() throws IllegalBlockSizeException, BadPaddingException
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).BadPaddingException
- if this cipher is a block cipher and unpadding fails.public final byte[] doFinal(byte[] input) throws IllegalBlockSizeException, BadPaddingException
input
- the input bufferIllegalBlockSizeException
- 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).BadPaddingException
- if this cipher is a block cipher and unpadding fails.public abstract byte[] doFinal(byte[] input, int inOff, int inLen) throws IllegalBlockSizeException, BadPaddingException
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthIllegalBlockSizeException
- 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).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 ShortBufferException, IllegalBlockSizeException, 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 storedShortBufferException
- if the output buffer is too small to hold the result.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).BadPaddingException
- if this cipher is a block cipher and unpadding fails.Copyright © 2020 BouncyCastle.org. All rights reserved.