public abstract class OpenSSLCipher extends CipherSpi
| Modifier and Type | Class and Description |
|---|---|
static class |
OpenSSLCipher.EVP_AEAD |
static class |
OpenSSLCipher.EVP_CIPHER |
protected static class |
OpenSSLCipher.Mode
Modes that a block cipher may support.
|
protected static class |
OpenSSLCipher.Padding
Paddings that a block cipher may support.
|
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
encodedKey
May be used when reseting the cipher instance after calling
doFinal. |
protected byte[] |
iv
The Initial Vector (IV) used for the current cipher.
|
protected OpenSSLCipher.Mode |
mode
The current cipher mode.
|
| Modifier | Constructor and Description |
|---|---|
protected |
OpenSSLCipher() |
protected |
OpenSSLCipher(OpenSSLCipher.Mode mode,
OpenSSLCipher.Padding padding) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
checkSupportedKeySize(int keySize)
Checks whether the cipher supports this particular
keySize (in
bytes) and throws InvalidKeyException if it doesn't. |
protected abstract void |
checkSupportedMode(OpenSSLCipher.Mode mode)
Checks whether the cipher supports this particular cipher
mode
and throws NoSuchAlgorithmException if it doesn't. |
protected abstract void |
checkSupportedPadding(OpenSSLCipher.Padding padding)
Checks whether the cipher supports this particular cipher
padding
and throws NoSuchPaddingException if it doesn't. |
protected abstract int |
doFinalInternal(byte[] output,
int outputOffset,
int maximumLen)
API-specific implementation of the final block.
|
protected byte[] |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen)
Finishes a multi-part transformation (encryption or decryption).
|
protected int |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
Finishes a multi-part transformation (encryption or decryption).
|
protected int |
engineGetBlockSize()
Returns the block size of this cipher (in bytes)
|
protected byte[] |
engineGetIV()
Returns the Initialization Vector (IV) that was used to initialize this
cipher or
null if none was used. |
protected int |
engineGetOutputSize(int inputLen)
Returns the size for a buffer (in bytes), that the next call to
update of doFinal would return, taking into account any buffered
data from previous update calls and padding. |
protected AlgorithmParameters |
engineGetParameters()
Returns the parameters that where used to create this cipher instance.
|
protected void |
engineInit(int opmode,
Key key,
AlgorithmParameterSpec params,
SecureRandom random)
Initializes this cipher instance with the specified key, algorithm
parameters and a source of randomness.
|
protected void |
engineInit(int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random)
Initializes this cipher instance with the specified key, algorithm
parameters and a source of randomness.
|
protected void |
engineInit(int opmode,
Key key,
SecureRandom random)
Initializes this cipher instance with the specified key and a source of
randomness.
|
protected abstract void |
engineInitInternal(byte[] encodedKey,
AlgorithmParameterSpec params,
SecureRandom random)
API-specific implementation of initializing the cipher.
|
protected void |
engineSetMode(String modeStr)
Sets the mode for this cipher.
|
protected void |
engineSetPadding(String paddingStr)
Sets the padding method for this cipher.
|
protected Key |
engineUnwrap(byte[] wrappedKey,
String wrappedKeyAlgorithm,
int wrappedKeyType)
Unwraps a key using this cipher instance.
|
protected byte[] |
engineUpdate(byte[] input,
int inputOffset,
int inputLen)
Continues a multi-part transformation (encryption or decryption).
|
protected int |
engineUpdate(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
Continues a multi-part transformation (encryption or decryption).
|
protected byte[] |
engineWrap(Key key)
Wraps a key using this cipher instance.
|
protected abstract String |
getBaseCipherName()
Returns the standard name for the particular algorithm.
|
protected abstract int |
getCipherBlockSize() |
protected abstract int |
getOutputSizeForFinal(int inputLen)
The size of output if
doFinal() is called with this
inputLen. |
protected abstract int |
getOutputSizeForUpdate(int inputLen)
The size of output if
update() is called with this
inputLen. |
protected OpenSSLCipher.Padding |
getPadding()
Returns the padding type for which this cipher is initialized.
|
protected boolean |
isEncrypting() |
protected boolean |
supportsVariableSizeIv() |
protected boolean |
supportsVariableSizeKey() |
protected abstract int |
updateInternal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset,
int maximumLen)
API-specific implementation of updating the cipher.
|
engineDoFinal, engineGetKeySize, engineUpdate, engineUpdateAAD, engineUpdateAADprotected OpenSSLCipher.Mode mode
protected byte[] encodedKey
doFinal.protected byte[] iv
protected OpenSSLCipher()
protected OpenSSLCipher(OpenSSLCipher.Mode mode, OpenSSLCipher.Padding padding)
protected abstract void engineInitInternal(byte[] encodedKey,
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidKeyException,
InvalidAlgorithmParameterException
isEncrypting() function will tell whether it should be
initialized for encryption or decryption. The encodedKey will be
the bytes of a supported key size.protected abstract int updateInternal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset,
int maximumLen)
throws ShortBufferException
maximumLen will be the maximum length of the output as returned
by getOutputSizeForUpdate(int). The return value must be the
number of bytes processed and placed into output. On error, an
exception must be thrown.ShortBufferExceptionprotected abstract int doFinalInternal(byte[] output,
int outputOffset,
int maximumLen)
throws IllegalBlockSizeException,
BadPaddingException,
ShortBufferException
maximumLen
will be the maximum length of the possible output as returned by
getOutputSizeForFinal(int). The return value must be the number
of bytes processed and placed into output. On error, an exception
must be thrown.protected abstract String getBaseCipherName()
protected abstract void checkSupportedKeySize(int keySize)
throws InvalidKeyException
keySize (in
bytes) and throws InvalidKeyException if it doesn't.InvalidKeyExceptionprotected abstract void checkSupportedMode(OpenSSLCipher.Mode mode) throws NoSuchAlgorithmException
mode
and throws NoSuchAlgorithmException if it doesn't.NoSuchAlgorithmExceptionprotected abstract void checkSupportedPadding(OpenSSLCipher.Padding padding) throws NoSuchPaddingException
padding
and throws NoSuchPaddingException if it doesn't.NoSuchPaddingExceptionprotected abstract int getCipherBlockSize()
protected boolean supportsVariableSizeKey()
protected boolean supportsVariableSizeIv()
protected void engineSetMode(String modeStr) throws NoSuchAlgorithmException
CipherSpiengineSetMode in class CipherSpimodeStr - the name of the cipher mode.NoSuchAlgorithmException - if the specified cipher mode is not supported by this
provider.protected void engineSetPadding(String paddingStr) throws NoSuchPaddingException
CipherSpiengineSetPadding in class CipherSpipaddingStr - the name of the padding method.NoSuchPaddingException - if the specified padding method is not supported by this
cipher.protected OpenSSLCipher.Padding getPadding()
protected int engineGetBlockSize()
CipherSpiengineGetBlockSize in class CipherSpiprotected abstract int getOutputSizeForFinal(int inputLen)
doFinal() is called with this
inputLen. If padding is enabled and the size of the input puts it
right at the block size, it will add another block for the padding.protected abstract int getOutputSizeForUpdate(int inputLen)
update() is called with this
inputLen. If padding is enabled and the size of the input puts it
right at the block size, it will add another block for the padding.protected int engineGetOutputSize(int inputLen)
CipherSpiupdate of doFinal would return, taking into account any buffered
data from previous update calls and padding.
The actual output length of the next call to update or doFinal may be smaller than the length returned by this method.
engineGetOutputSize in class CipherSpiinputLen - the length of the input (in bytes).protected byte[] engineGetIV()
CipherSpinull if none was used.engineGetIV in class CipherSpinull if none was used.protected AlgorithmParameters engineGetParameters()
CipherSpiThese may be a the same parameters that were used to create this cipher instance, or may be a combination of default and random parameters, depending on the underlying cipher implementation.
engineGetParameters in class CipherSpinull if this cipher instance does not have any parameters
at all.protected void engineInit(int opmode,
Key key,
SecureRandom random)
throws InvalidKeyException
CipherSpi
The cipher will be initialized for the specified operation (one of:
encryption, decryption, key wrapping or key unwrapping) depending on
opmode.
If this cipher instance needs any algorithm parameters or random values
that the specified key cannot provide, the underlying implementation of
this cipher is supposed to generate the required parameters (using its
provider or random values). Random values will be generated using random;
When a cipher instance is initialized by a call to any of the init methods, the state of the instance is overridden, means it is
equivalent to creating a new instance and calling it init method.
engineInit in class CipherSpiopmode - the operation this cipher instance should be initialized for
(one of: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE).key - the input key for the operation.random - the source of randomness to use.InvalidKeyException - if the specified key cannot be used to initialize this cipher
instance.protected void engineInit(int opmode,
Key key,
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidKeyException,
InvalidAlgorithmParameterException
CipherSpi
The cipher will be initialized for the specified operation (one of:
encryption, decryption, key wrapping or key unwrapping) depending on
opmode.
If this cipher instance needs any algorithm parameters and params
is null, the underlying implementation of this cipher is supposed
to generate the required parameters (using its provider or random
values). Random values are generated using random.
When a cipher instance is initialized by a call to any of the init methods, the state of the instance is overridden, means it is
equivalent to creating a new instance and calling it init method.
engineInit in class CipherSpiopmode - the operation this cipher instance should be initialized for
(one of: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE).key - the input key for the operation.params - the algorithm parameters.random - the source of randomness to use.InvalidKeyException - if the specified key cannot be used to initialize this cipher
instance.InvalidAlgorithmParameterException - it the specified parameters are inappropriate for this
cipher.protected void engineInit(int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random)
throws InvalidKeyException,
InvalidAlgorithmParameterException
CipherSpi
The cipher will be initialized for the specified operation (one of:
encryption, decryption, key wrapping or key unwrapping) depending on
opmode.
If this cipher instance needs any algorithm parameters and params
is null, the underlying implementation of this cipher is supposed
to generate the required parameters (using its provider or random
values). Random values are generated using random.
When a cipher instance is initialized by a call to any of the init methods, the state of the instance is overridden, means it is
equivalent to creating a new instance and calling it init method.
engineInit in class CipherSpiopmode - the operation this cipher instance should be initialized for
(one of: ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE or UNWRAP_MODE).key - the input key for the operation.params - the algorithm parameters.random - the source of randomness to use.InvalidKeyException - if the specified key cannot be used to initialize this cipher
instance.InvalidAlgorithmParameterException - if the specified parameters are inappropriate for this
cipher.protected byte[] engineUpdate(byte[] input,
int inputOffset,
int inputLen)
CipherSpiengineUpdate in class CipherSpiinput - the input bytes to transform.inputOffset - the offset in the input to start.inputLen - the length of the input to transform.null if the
input has zero length.protected int engineUpdate(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
throws ShortBufferException
CipherSpioutput buffer.
If the size of the output buffer is too small to hold the result,
a ShortBufferException is thrown. Use
getOutputSize to check for the size of the
output buffer.
engineUpdate in class CipherSpiinput - the input bytes to transform.inputOffset - the offset in the input to start.inputLen - the length of the input to transform.output - the output buffer.outputOffset - the offset in the output buffer.ShortBufferException - if the size of the output buffer is too small.protected byte[] engineDoFinal(byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException,
BadPaddingException
CipherSpi
Processes the inputLen bytes in input buffer at inputOffset, and any bytes that have been buffered in previous update calls.
engineDoFinal in class CipherSpiinput - the input buffer.inputOffset - the offset in the input buffer.inputLen - the length of the input.IllegalBlockSizeException - if the size of the resulting bytes is not a multiple of the
cipher block size.BadPaddingException - if the padding of the data does not match the padding scheme.protected int engineDoFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
throws ShortBufferException,
IllegalBlockSizeException,
BadPaddingException
CipherSpi
Processes the inputLen bytes in input buffer at
inputOffset, and any bytes that have been buffered in previous
update calls.
engineDoFinal in class CipherSpiinput - the input buffer.inputOffset - the offset in the input buffer.inputLen - the length of the input.output - the output buffer for the transformed bytes.outputOffset - the offset in the output buffer.ShortBufferException - if the size of the output buffer is too small.IllegalBlockSizeException - if the size of the resulting bytes is not a multiple of the
cipher block size.BadPaddingException - if the padding of the data does not match the padding scheme.protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException
CipherSpiUnsupportedOperationException.engineWrap in class CipherSpikey - the key to wrap.IllegalBlockSizeException - if the size of the resulting bytes is not a multiple of the
cipher block size.InvalidKeyException - if this cipher instance cannot wrap this key.protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException
CipherSpi
This method has been added to this class (for backwards compatibility, it
cannot be abstract). If this method is not overridden, it throws an
UnsupportedOperationException.
engineUnwrap in class CipherSpiwrappedKey - the wrapped key to unwrap.wrappedKeyAlgorithm - the algorithm for the wrapped key.wrappedKeyType - the type of the wrapped key (one of: SECRET_KEY,
PRIVATE_KEY or PUBLIC_KEY)InvalidKeyException - if the wrappedKey cannot be unwrapped to a key of
type wrappedKeyType for the wrappedKeyAlgorithm.NoSuchAlgorithmException - if no provider can be found that can create a key of type
wrappedKeyType for the wrappedKeyAlgorithm.protected boolean isEncrypting()