public abstract class AsymmetricHybridCipher extends CipherSpiExt
Modifier and Type | Field and Description |
---|---|
protected java.security.spec.AlgorithmParameterSpec |
paramSpec
ParameterSpec used with this cipher
|
DECRYPT_MODE, ENCRYPT_MODE, opMode
Constructor and Description |
---|
AsymmetricHybridCipher() |
Modifier and Type | Method and Description |
---|---|
protected abstract int |
decryptOutputSize(int inLen)
Compute the output size of an update() or doFinal() operation of a hybrid
asymmetric cipher in decryption mode when given input of the specified
length.
|
abstract byte[] |
doFinal(byte[] input,
int inOff,
int inLen)
Finish a multiple-part encryption or decryption operation (depending on
how this cipher was initialized).
|
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 abstract int |
encryptOutputSize(int inLen)
Compute the output size of an update() or doFinal() operation of a hybrid
asymmetric cipher in encryption mode when given input of the specified
length.
|
int |
getBlockSize() |
byte[] |
getIV()
Return the initialization vector.
|
int |
getOutputSize(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 inLen (in bytes).
|
java.security.spec.AlgorithmParameterSpec |
getParameters()
Return the parameters used with this cipher.
|
protected abstract void |
initCipherDecrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Initialize the AsymmetricHybridCipher with a certain key for data
encryption.
|
protected abstract void |
initCipherEncrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom sr)
Initialize the AsymmetricHybridCipher with a certain key for data
encryption.
|
void |
initDecrypt(java.security.Key key)
Initialize the cipher for decryption by forwarding it to initDecrypt(Key,
FlexiSecureRandom).
|
void |
initDecrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Initialize the cipher with a certain key for data decryption.
|
void |
initEncrypt(java.security.Key key)
Initialize the cipher for encryption by forwarding it to
initEncrypt(Key, AlgorithmParameterSpec, SecureRandom) . |
void |
initEncrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params)
Initialize the cipher for encryption by forwarding it to initEncrypt(Key,
FlexiSecureRandom, AlgorithmParameterSpec).
|
void |
initEncrypt(java.security.Key key,
java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initialize the cipher with a certain key for data encryption.
|
void |
initEncrypt(java.security.Key key,
java.security.SecureRandom random)
Initialize this cipher for encryption by forwarding it to
initEncrypt(Key, AlgorithmParameterSpec, SecureRandom) . |
protected void |
setMode(java.lang.String modeName)
Since asymmetric hybrid ciphers do not support modes, this method does
nothing.
|
protected void |
setPadding(java.lang.String paddingName)
Since asymmetric hybrid ciphers do not support padding, this method does
nothing.
|
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.
|
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.
|
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, getKeySize, getName, update
protected java.security.spec.AlgorithmParameterSpec paramSpec
protected final void setMode(java.lang.String modeName)
setMode
in class CipherSpiExt
modeName
- the cipher mode (unused)protected final void setPadding(java.lang.String paddingName)
setPadding
in class CipherSpiExt
paddingName
- the name of the padding scheme (not used)public final byte[] getIV()
CipherSpiExt
getIV
in class CipherSpiExt
public final int getBlockSize()
getBlockSize
in class CipherSpiExt
public final 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).
getParameters
in class CipherSpiExt
public final int getOutputSize(int inLen)
getOutputSize
in class CipherSpiExt
inLen
- the length of the inputpublic final void initEncrypt(java.security.Key key) throws java.security.InvalidKeyException
initEncrypt(Key, AlgorithmParameterSpec, SecureRandom)
.
If this cipher requires any algorithm parameters that cannot be derived
from the given key, 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
InvalidKeyException if it is being initialized for decryption. The
generated parameters can be retrieved using getParameters()
.
key
- the encryption keyjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipher.java.security.InvalidParameterException
- if this cipher needs algorithm parameters for
initialization and cannot generate parameters itself.public final void initEncrypt(java.security.Key key, java.security.SecureRandom random) throws java.security.InvalidKeyException
initEncrypt(Key, AlgorithmParameterSpec, SecureRandom)
.
If this cipher requires any algorithm parameters that cannot be derived
from the given key, 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
InvalidKeyException if it is being initialized for decryption. The
generated parameters can be retrieved using getParameters()
.
key
- the encryption keyrandom
- the source of randomnessjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipher.java.security.InvalidParameterException
- if this cipher needs algorithm parameters for
initialization and cannot generate parameters itself.public final void initEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
key
- the encryption keyparams
- the algorithm parametersjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipher.java.security.InvalidAlgorithmParameterException
- if the given algorithm parameters are inappropriate for
this cipher, or if this cipher is initialized with
null parameters and cannot generate parameters
itself.public final void initEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If this cipher 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.
initEncrypt
in class CipherSpiExt
key
- the encryption keyrandom
- the source of randomnessparams
- the algorithm parametersjava.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 initialized with
null parameters and cannot generate parameters
itself.public final void initDecrypt(java.security.Key key) throws java.security.InvalidKeyException
If this cipher requires any algorithm parameters that cannot be derived
from the given key, 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
InvalidKeyException if it is being initialized for decryption. The
generated parameters can be retrieved using getParameters()
.
key
- the decryption keyjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipher.public final void initDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
If this cipher 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
initDecrypt
in class CipherSpiExt
key
- the decryption keyparams
- the algorithm parametersjava.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 initialized with
null parameters and cannot generate parameters
itself.public abstract byte[] update(byte[] input, int inOff, int inLen)
update
in class CipherSpiExt
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthpublic final int update(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException
update
in class CipherSpiExt
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 abstract byte[] doFinal(byte[] input, int inOff, int inLen) throws javax.crypto.BadPaddingException
doFinal
in class CipherSpiExt
input
- the input bufferinOff
- the offset where the input startsinLen
- the input lengthjavax.crypto.BadPaddingException
- if the ciphertext is invalid.public final int doFinal(byte[] input, int inOff, int inLen, byte[] output, int outOff) throws javax.crypto.ShortBufferException, javax.crypto.BadPaddingException
doFinal
in class CipherSpiExt
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.BadPaddingException
- if the ciphertext is invalid.protected abstract int encryptOutputSize(int inLen)
inLen
- the length of the inputprotected abstract int decryptOutputSize(int inLen)
inLen
- the length of the inputprotected abstract void initCipherEncrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom sr) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
key
- the key which has to be used to encrypt dataparams
- the algorithm parameterssr
- the source of randomnessjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipher.java.security.InvalidAlgorithmParameterException
- if the given parameters are inappropriate for
initializing this cipher.protected abstract void initCipherDecrypt(java.security.Key key, java.security.spec.AlgorithmParameterSpec params) throws java.security.InvalidKeyException, java.security.InvalidAlgorithmParameterException
key
- the key which has to be used to decrypt dataparams
- the algorithm parametersjava.security.InvalidKeyException
- if the given key is inappropriate for initializing this
cipherjava.security.InvalidAlgorithmParameterException
- if the given parameters are inappropriate for
initializing this cipher.