Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.crypto.CipherSpi
Providers of cryptographic ciphers must subclass this for every
cipher they implement, implementing the abstract methods as
appropriate, then provide an entry that points to the subclass in
their implementation of Provider
.
CipherSpi objects are instantiated along with Cipher
s when
the Cipher.getInstance(String)
methods are invoked.
Particular ciphers are referenced by a transformation, which
is a String consisting of the cipher's name or the ciper's name
followed by a mode and a padding. Transformations all follow the
general form:
Cipher names in the master Provider
class
may be:
Cipher.algorithm
Cipher.algorithm/mode
Cipher.algorithm//padding
Cipher.algorithm/mode/padding
When any Cipher.getInstance(String)
method is
invoked, the following happens if the transformation is simply
algorithm:
CipherSpi
implementation
for "algorithm", return it. Otherwise throw a NoSuchAlgorithmException
.If the transformation is of the form algorithm/mode/padding:
CipherSpi
subclass for
"algorithm/mode/padding", return it. Otherwise
go to step 2.CipherSpi
subclass for
"algorithm/mode", instatiate it, call engineSetPadding(String)
for the padding name, and return
it. Otherwise go to step 3.CipherSpi
subclass for
"algorithm//padding", instatiate it, call engineSetMode(String)
for the mode name, and return
it. Otherwise go to step 4.CipherSpi
subclass for
"algorithm", instatiate it, call engineSetMode(String)
for the mode name, call engineSetPadding(String)
for the padding name, and return
it. Otherwise throw a NoSuchAlgorithmException
.Constructor Summary | |
|
Method Summary | |
protected abstract byte[] |
|
protected abstract int |
|
protected int |
|
protected abstract int |
|
protected abstract byte[] |
|
protected int |
|
protected abstract int |
|
protected abstract AlgorithmParameters |
|
protected abstract void |
|
protected abstract void |
|
protected abstract void |
|
protected abstract void |
|
protected abstract void |
|
protected Key |
|
protected abstract byte[] |
|
protected abstract int |
|
protected int |
|
protected byte[] |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
protected abstract byte[] engineDoFinal(byte[] input, int inputOffset, int inputLength) throws IllegalBlockSizeException, BadPaddingException
Finishes a multi-part transformation or transforms a portion of a byte array, and returns the transformed bytes.
- Parameters:
input
- The input bytes.inputOffset
- The index in the input at which to start.inputLength
- The number of bytes to transform.
- Returns:
- The transformed bytes in a new array.
- Throws:
IllegalBlockSizeException
- If this instance has no padding and the input size is not a multiple of the block size.BadPaddingException
- If this instance is being used for decryption and the padding is not appropriate for this instance's padding scheme.
protected abstract int engineDoFinal(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException
Finishes a multi-part transformation or transforms a portion of a byte array, and stores the transformed bytes in the supplied array.
- Parameters:
input
- The input bytes.inputOffset
- The index in the input at which to start.inputLength
- The number of bytes to transform.output
- The output byte array.outputOffset
- The index in the output array at which to start.
- Returns:
- The number of transformed bytes stored in the output array.
- Throws:
IllegalBlockSizeException
- If this instance has no padding and the input size is not a multiple of the block size.BadPaddingException
- If this instance is being used for decryption and the padding is not appropriate for this instance's padding scheme.ShortBufferException
- If there is not enough space in the output array for the transformed bytes.
protected int engineDoFinal(ByteBuffer input, ByteBuffer output) throws BadPaddingException, IllegalBlockSizeException, ShortBufferException
- Since:
- 1.5
protected abstract int engineGetBlockSize()
Returns the block size of the underlying cipher.
- Returns:
- The block size.
protected abstract byte[] engineGetIV()
Returns the initializaiton vector this cipher was initialized with, if any.
- Returns:
- The IV, or null if this cipher uses no IV or if this instance has not been initialized yet.
protected int engineGetKeySize(Key key) throws InvalidKeyException
Return the length of the given key in bits.For compatibility this method is not declared
abstract
, and the default implementation will throw anUnsupportedOperationException
. Concrete subclasses should override this method to return the correct value.
- Parameters:
key
- The key to get the size for.
- Returns:
- The size of the key, in bits.
- Throws:
InvalidKeyException
- If the key's length cannot be determined by this implementation.
protected abstract int engineGetOutputSize(int inputLength)
Returns the size, in bytes, an output buffer must be for a call toengineUpdate(byte[],int,int,byte[],int)
orengineDoFinal(byte[],int,int,byte[],int)
to succeed.The actual output length may be smaller than the value returned by this method, as it considers the padding length as well. The length considered is the argument plus the length of any buffered, unprocessed bytes.
- Parameters:
inputLength
- The input length, in bytes.
- Returns:
- The size an output buffer must be.
protected abstract AlgorithmParameters engineGetParameters()
Returns the parameters that this cipher is using. This may be the parameters used to initialize this cipher, or it may be parameters that have been initialized with random values.
- Returns:
- This cipher's parameters, or
null
if this cipher does not use parameters.
protected abstract void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidAlgorithmParameterException, InvalidKeyException
Initializes this cipher with an operation mode, key, parameters, and source of randomness. If this cipher requires any other initializing data, for example an initialization vector, then it should generate it from the provided source of randomness.
- Parameters:
opmode
- The operation mode, one ofCipher.DECRYPT_MODE
,Cipher.ENCRYPT_MODE
,Cipher.UNWRAP_MODE
, orCipher.WRAP_MODE
.key
- The key to initialize this cipher with.params
- The algorithm parameters to initialize with.random
- The source of random bytes to use.
- Throws:
InvalidAlgorithmParameterException
- If the given parameters are not appropriate for this implementation.InvalidKeyException
- If the given key is not acceptable for this implementation.
protected abstract void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException
Initializes this cipher with an operation mode, key, and source of randomness. If this cipher requires any other initializing data, for example an initialization vector, then it should generate it from the provided source of randomness.
- Parameters:
opmode
- The operation mode, one ofCipher.DECRYPT_MODE
,Cipher.ENCRYPT_MODE
,Cipher.UNWRAP_MODE
, orCipher.WRAP_MODE
.key
- The key to initialize this cipher with.random
- The source of random bytes to use.
- Throws:
InvalidKeyException
- If the given key is not acceptable for this implementation.
protected abstract void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException, InvalidKeyException
Initializes this cipher with an operation mode, key, parameters, and source of randomness. If this cipher requires any other initializing data, for example an initialization vector, then it should generate it from the provided source of randomness.
- Parameters:
opmode
- The operation mode, one ofCipher.DECRYPT_MODE
,Cipher.ENCRYPT_MODE
,Cipher.UNWRAP_MODE
, orCipher.WRAP_MODE
.key
- The key to initialize this cipher with.params
- The algorithm parameters to initialize with.random
- The source of random bytes to use.
- Throws:
InvalidAlgorithmParameterException
- If the given parameters are not appropriate for this implementation.InvalidKeyException
- If the given key is not acceptable for this implementation.
protected abstract void engineSetMode(String mode) throws NoSuchAlgorithmException
Set the mode in which this cipher is to run.
- Parameters:
mode
- The name of the mode to use.
- Throws:
NoSuchAlgorithmException
- If the mode is not supported by this cipher's provider.
protected abstract void engineSetPadding(String padding) throws NoSuchPaddingException
Set the method with which the input is to be padded.
- Parameters:
padding
- The name of the padding to use.
- Throws:
NoSuchPaddingException
- If the padding is not supported by this cipher's provider.
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException
Unwraps a previously-wrapped key.For compatibility this method is not declared
abstract
, and the default implementation will throw anUnsupportedOperationException
.
- Parameters:
wrappedKey
- The wrapped key.wrappedKeyAlgorithm
- The name of the algorithm used to wrap this key.wrappedKeyType
- The type of wrapped key; one ofCipher.PRIVATE_KEY
,Cipher.PUBLIC_KEY
, orCipher.SECRET_KEY
.
- Returns:
- The unwrapped key.
- Throws:
InvalidKeyException
- If the key cannot be unwrapped, or ifwrappedKeyType
is an inappropriate type for the unwrapped key.NoSuchAlgorithmException
- If thewrappedKeyAlgorithm
is unknown.
protected abstract byte[] engineUpdate(byte[] input, int inputOffset, int inputLength)
Continue with a multi-part transformation, returning a new array of the transformed bytes.
- Parameters:
input
- The next input bytes.inputOffset
- The index in the input array from which to start.inputLength
- The number of bytes to input.
- Returns:
- The transformed bytes.
protected abstract int engineUpdate(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) throws ShortBufferException
Continue with a multi-part transformation, storing the transformed bytes into the specified array.
- Parameters:
input
- The next input bytes.inputOffset
- The index in the input from which to start.inputLength
- The number of bytes to input.output
- The output buffer.outputOffset
- The index in the output array from which to start.
- Returns:
- The transformed bytes.
- Throws:
ShortBufferException
- If there is not enough space in the output array to store the transformed bytes.
protected int engineUpdate(ByteBuffer input, ByteBuffer output) throws ShortBufferException
- Since:
- 1.5
protected byte[] engineWrap(Key key) throws InvalidKeyException, IllegalBlockSizeException
Wrap a key.For compatibility this method is not declared
abstract
, and the default implementation will throw anUnsupportedOperationException
.
- Parameters:
key
- The key to wrap.
- Returns:
- The wrapped key.
- Throws:
InvalidKeyException
- If the key cannot be wrapped.