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) |
protected int |
engineDoFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset) |
protected int |
engineGetBlockSize() |
protected byte[] |
engineGetIV() |
protected int |
engineGetOutputSize(int inputLen) |
protected AlgorithmParameters |
engineGetParameters() |
protected void |
engineInit(int opmode,
Key key,
AlgorithmParameterSpec params,
SecureRandom random) |
protected void |
engineInit(int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random) |
protected void |
engineInit(int opmode,
Key key,
SecureRandom random) |
protected abstract void |
engineInitInternal(byte[] encodedKey,
AlgorithmParameterSpec params,
SecureRandom random)
API-specific implementation of initializing the cipher.
|
protected void |
engineSetMode(String modeStr) |
protected void |
engineSetPadding(String paddingStr) |
protected Key |
engineUnwrap(byte[] wrappedKey,
String wrappedKeyAlgorithm,
int wrappedKeyType) |
protected byte[] |
engineUpdate(byte[] input,
int inputOffset,
int inputLen) |
protected int |
engineUpdate(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset) |
protected byte[] |
engineWrap(Key key) |
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
engineSetMode in class CipherSpiNoSuchAlgorithmExceptionprotected void engineSetPadding(String paddingStr) throws NoSuchPaddingException
engineSetPadding in class CipherSpiNoSuchPaddingExceptionprotected OpenSSLCipher.Padding getPadding()
protected int engineGetBlockSize()
engineGetBlockSize 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)
engineGetOutputSize in class CipherSpiprotected byte[] engineGetIV()
engineGetIV in class CipherSpiprotected AlgorithmParameters engineGetParameters()
engineGetParameters in class CipherSpiprotected void engineInit(int opmode,
Key key,
SecureRandom random)
throws InvalidKeyException
engineInit in class CipherSpiInvalidKeyExceptionprotected void engineInit(int opmode,
Key key,
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidKeyException,
InvalidAlgorithmParameterException
engineInit in class CipherSpiInvalidKeyExceptionInvalidAlgorithmParameterExceptionprotected void engineInit(int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random)
throws InvalidKeyException,
InvalidAlgorithmParameterException
engineInit in class CipherSpiInvalidKeyExceptionInvalidAlgorithmParameterExceptionprotected byte[] engineUpdate(byte[] input,
int inputOffset,
int inputLen)
engineUpdate in class CipherSpiprotected int engineUpdate(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
throws ShortBufferException
engineUpdate in class CipherSpiShortBufferExceptionprotected byte[] engineDoFinal(byte[] input,
int inputOffset,
int inputLen)
throws IllegalBlockSizeException,
BadPaddingException
engineDoFinal in class CipherSpiIllegalBlockSizeExceptionBadPaddingExceptionprotected int engineDoFinal(byte[] input,
int inputOffset,
int inputLen,
byte[] output,
int outputOffset)
throws ShortBufferException,
IllegalBlockSizeException,
BadPaddingException
engineDoFinal in class CipherSpiShortBufferExceptionIllegalBlockSizeExceptionBadPaddingExceptionprotected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException
engineWrap in class CipherSpiIllegalBlockSizeExceptionInvalidKeyExceptionprotected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException
engineUnwrap in class CipherSpiInvalidKeyExceptionNoSuchAlgorithmExceptionprotected boolean isEncrypting()