|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--javax.crypto.CipherSpi
|
+--de.flexiprovider.api.Cipher
|
+--de.flexiprovider.api.BlockCipher
The BlockCipher class extends CipherSpi and handles the creation of PaddingScheme, BlockCipher and Mode. An instance of this class will be created by the Cipher.getInstance(String)-mechanism of the Cipher class.
BlockCipher ensures that a Mode and a PaddingsScheme are created, even if the user has set no preferences. For this to work, BlockCipher requires version 1.3 of the mode class that can handle a getInstance()-call without arguments to return a default Mode or Padding.
BlockCipher will acknowledge only one call of engineSetMode() and engineSetPadding() to ensure that these settings aren't changed while encrypting.
| Field Summary | |
protected SecureRandom |
random
the source of randomness, if necessary |
| Fields inherited from class de.flexiprovider.api.Cipher |
DECRYPT_MODE, ENCRYPT_MODE, opMode |
| Constructor Summary | |
BlockCipher()
|
|
| Method Summary | |
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 void |
engineInit(int opmode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec,
java.security.SecureRandom javaRand)
Initialize this cipher object with proper key and algorithm parameters, and some random seed. |
int |
getBlockSize()
|
protected abstract int |
getCipherBlockSize()
Return the blocksize the algorithm uses. |
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 inputLen (in bytes). |
AlgorithmParameterSpec |
getParameters()
Return the parameters used with this cipher. |
protected abstract void |
initCipherDecrypt(SecretKey key,
AlgorithmParameterSpec params)
Initialize the block cipher with a secret key and parameters for data decryption. |
protected abstract void |
initCipherEncrypt(SecretKey key,
AlgorithmParameterSpec params)
Initialize the block cipher with a secret key and parameters for data encryption. |
void |
initDecrypt(Key key)
Initialize this cipher with a key and a source of randomness for decryption. |
void |
initDecrypt(Key key,
AlgorithmParameterSpec cipherParams)
Initialize this cipher with a key, a set of algorithm parameters, and a source of randomness for decryption. |
void |
initDecrypt(Key key,
ModeParameterSpec modeParams,
AlgorithmParameterSpec cipherParams)
Initialize this cipher with a key, a set of algorithm parameters, and a source of randomness for decryption. |
void |
initEncrypt(Key key)
Initialize this cipher with a key and a source of randomness for encryption. |
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. |
void |
initEncrypt(Key key,
ModeParameterSpec modeParams,
AlgorithmParameterSpec cipherParams,
SecureRandom random)
Initialize this cipher with a key, a set of algorithm parameters, and a source of randomness for encryption. |
void |
initEncrypt(Key key,
SecureRandom random)
Initialize this cipher with a key and a source of randomness for encryption. |
void |
setMode(java.lang.String modeName)
Set the mode of this cipher. |
void |
setPadding(java.lang.String paddingName)
Set the padding scheme of this cipher. |
protected abstract void |
singleBlockDecrypt(byte[] input,
int inOff,
byte[] output,
int outOff)
Decrypt a single block of data. |
protected abstract void |
singleBlockEncrypt(byte[] input,
int inOff,
byte[] output,
int outOff)
Encrypt a single block of data. |
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. |
| Methods inherited from class de.flexiprovider.api.Cipher |
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, getKeySize, getName, update |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
protected SecureRandom random
| Constructor Detail |
public BlockCipher()
| Method Detail |
protected final void engineInit(int opmode,
java.security.Key key,
java.security.spec.AlgorithmParameterSpec paramSpec,
java.security.SecureRandom javaRand)
throws java.security.InvalidKeyException,
java.security.InvalidAlgorithmParameterException
engineInit in class Cipheropmode - the operation mode for which this cipher is used
(ENCRYPT_MODE or DECRYPT_MODE)key - the keyparamSpec - the algorithm parametersjavaRand - 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.
public final void setMode(java.lang.String modeName)
throws NoSuchModeException
setMode in class CiphermodeName - the cipher modeNoSuchModeException - if neither the mode with the given name nor the default
mode can be found
public final void setPadding(java.lang.String paddingName)
throws NoSuchPaddingException
setPadding in class CipherpaddingName - the padding schemeNoSuchPaddingException - if the requested padding scheme cannot be found.public final byte[] getIV()
getIV in class Cipherprotected abstract int getCipherBlockSize()
public final int getBlockSize()
getBlockSize in class Cipherpublic final int getOutputSize(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.
getOutputSize in class CipherinLen - the input length (in bytes)public final 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 Cipher
public final void initEncrypt(Key key)
throws InvalidKeyException,
InvalidParameterException
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 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 BlockCipher 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 keyInvalidKeyException - if the given key is inappropriate for initializing this
cipherInvalidParameterException - if this block cipher requires parameters for
initialization and cannot generate parameters itself.
public final void initEncrypt(Key key,
SecureRandom random)
throws InvalidKeyException,
InvalidParameterException
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 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 and they will be stored in the class variable rndBytes.
Note that when a BlockCipher 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 keyrandom - the source of randomnessInvalidKeyException - if the given key is inappropriate for initializing this
cipherInvalidParameterException - if this block cipher requires parameters for
initialization and cannot generate parameters itself.
public final 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 BlockCipher 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 Cipherkey - 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 final void initEncrypt(Key key,
ModeParameterSpec modeParams,
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 BlockCipher 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 keymodeParams - the mode parameterscipherParams - 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 final void initDecrypt(Key key)
throws InvalidKeyException,
InvalidParameterException
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 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 BlockCipher 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 keyInvalidKeyException - if the given key is inappropriate for initializing this
cipherInvalidParameterException - if the parameters are
public final 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 BlockCipher 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 Cipherkey - 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 final void initDecrypt(Key key,
ModeParameterSpec modeParams,
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 BlockCipher 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 keymodeParams - the mode parameterscipherParams - 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 final byte[] update(byte[] input,
int inOff,
int inLen)
update in class Cipherinput - the input bufferinOff - the offset where the input startsinLen - the input length
public final int update(byte[] input,
int inOff,
int inLen,
byte[] output,
int outOff)
throws ShortBufferException
update in class Cipherinput - 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(byte[] input,
int inOff,
int inLen)
throws IllegalBlockSizeException,
BadPaddingException
doFinal in class Cipherinput - the input bufferinOff - the offset where the input startsinLen - the input lengthIllegalBlockSizeException - if the total input length is not a multiple of the block
size (for encryption when no padding is used or for
decryption).BadPaddingException - if unpadding fails.
public final int doFinal(byte[] input,
int inOff,
int inLen,
byte[] output,
int outOff)
throws ShortBufferException,
IllegalBlockSizeException,
BadPaddingException
doFinal in class Cipherinput - 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 the total input length is not a multiple of the block
size (for encryption when no padding is used or for
decryption).BadPaddingException - if unpadding fails.
protected abstract void initCipherEncrypt(SecretKey key,
AlgorithmParameterSpec params)
throws InvalidKeyException,
InvalidAlgorithmParameterException
key - the secret keyparams - the parametersInvalidKeyException - if the given key is inappropriate for this cipher.InvalidAlgorithmParameterException - if the given parameters are inappropriate for this
cipher.
protected abstract void initCipherDecrypt(SecretKey key,
AlgorithmParameterSpec params)
throws InvalidKeyException,
InvalidAlgorithmParameterException
key - the secret keyparams - the parametersInvalidKeyException - if the given key is inappropriate for this cipher.InvalidAlgorithmParameterException - if the given parameters are inappropriate for this
cipher.
protected abstract void singleBlockEncrypt(byte[] input,
int inOff,
byte[] output,
int outOff)
input - array of bytes which contains the plaintext to be
encryptedinOff - index in array in, where the plaintext block startsoutput - array of bytes which will contain the ciphertext startig
at outOffsetoutOff - index in array out, where the ciphertext block will start
protected abstract void singleBlockDecrypt(byte[] input,
int inOff,
byte[] output,
int outOff)
input - array of bytes which contains the ciphertext to be
decryptedinOff - index in array in, where the ciphertext block startsoutput - array of bytes which will contain the plaintext starting
at outOffsetoutOff - index in array out, where the plaintext block will start
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||