public final class

AESWrapCipher

extends CipherSpi
java.lang.Object
   ↳ javax.crypto.CipherSpi
     ↳ com.sun.crypto.provider.AESWrapCipher

Summary

Public Constructors
AESWrapCipher()
Creates an instance of AES KeyWrap cipher with default mode, i.e.
Protected Methods
byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
This operation is not supported by this cipher.
int engineDoFinal(byte[] in, int inOffset, int inLen, byte[] out, int outOffset)
This operation is not supported by this cipher.
int engineGetBlockSize()
Returns the block size (in bytes).
byte[] engineGetIV()
Returns the initialization vector (IV) which is null for this cipher.
int engineGetKeySize(Key key)
Returns the key size of the given key object in number of bits.
int engineGetOutputSize(int inputLen)
Returns the length in bytes that an output buffer would need to be given the input length inputLen (in bytes).
AlgorithmParameters engineGetParameters()
Returns the parameters used with this cipher which is always null for this cipher.
void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random)
Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
void engineInit(int opmode, Key key, SecureRandom random)
Initializes this cipher with a key and a source of randomness.
void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random)
Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
void engineSetMode(String mode)
Sets the mode of this cipher.
void engineSetPadding(String padding)
Sets the padding mechanism of this cipher.
Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType)
Unwrap a previously wrapped key.
int engineUpdate(byte[] in, int inOffset, int inLen, byte[] out, int outOffset)
This operation is not supported by this cipher.
byte[] engineUpdate(byte[] in, int inOffset, int inLen)
This operation is not supported by this cipher.
byte[] engineWrap(Key key)
Wrap a key.
[Expand]
Inherited Methods
From class javax.crypto.CipherSpi
From class java.lang.Object

Public Constructors

public AESWrapCipher ()

Creates an instance of AES KeyWrap cipher with default mode, i.e. "ECB" and padding scheme, i.e. "NoPadding".

Throws
SecurityException if this constructor fails to verify its own integrity

Protected Methods

protected byte[] engineDoFinal (byte[] input, int inputOffset, int inputLen)

This operation is not supported by this cipher. Since it's impossible to initialize this cipher given the current Cipher.engineInit(...) implementation, IllegalStateException will always be thrown upon invocation.

Parameters
input the input buffer
inputOffset the offset in input where the input starts
inputLen the input length
Returns
  • n/a.

protected int engineDoFinal (byte[] in, int inOffset, int inLen, byte[] out, int outOffset)

This operation is not supported by this cipher. Since it's impossible to initialize this cipher given the current Cipher.engineInit(...) implementation, IllegalStateException will always be thrown upon invocation.

Parameters
in the input buffer.
inOffset the offset in in where the input starts.
inLen the input length.
out the buffer for the result.
outOffset the ofset in out where the result is stored.
Returns
  • n/a.

protected int engineGetBlockSize ()

Returns the block size (in bytes). i.e. 16 bytes.

Returns
  • the block size (in bytes), i.e. 16 bytes.

protected byte[] engineGetIV ()

Returns the initialization vector (IV) which is null for this cipher.

Returns
  • null for this cipher.

protected int engineGetKeySize (Key key)

Returns the key size of the given key object in number of bits.

Parameters
key the key object.
Returns
  • the "effective" key size of the given key object.
Throws
InvalidKeyException if key is invalid.

protected int engineGetOutputSize (int inputLen)

Returns the length in bytes that an output buffer would need to be given the input length inputLen (in bytes).

The actual output length of the next update or doFinal call may be smaller than the length returned by this method.

Parameters
inputLen the input length (in bytes)
Returns
  • the required output buffer size (in bytes)

protected AlgorithmParameters engineGetParameters ()

Returns the parameters used with this cipher which is always null for this cipher.

Returns
  • null since this cipher does not use any parameters.

protected void engineInit (int opmode, Key key, AlgorithmParameters params, SecureRandom random)

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

The cipher only supports the following two operation modes: Cipher.WRAP_MODE, and Cipher.UNWRAP_MODE.

For modes other than the above two, UnsupportedOperationException will be thrown.

Parameters
opmode the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.
key the secret key.
params the algorithm parameters; must be null for this cipher.
random the source of randomness.
Throws
InvalidKeyException if the given key is inappropriate.
InvalidAlgorithmParameterException if the given algorithm parameters is not null.

protected void engineInit (int opmode, Key key, SecureRandom random)

Initializes this cipher with a key and a source of randomness.

The cipher only supports the following two operation modes: Cipher.WRAP_MODE, and Cipher.UNWRAP_MODE.

For modes other than the above two, UnsupportedOperationException will be thrown.

Parameters
opmode the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.
key the secret key.
random the source of randomness.
Throws
InvalidKeyException if the given key is inappropriate for initializing this cipher.

protected void engineInit (int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random)

Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

The cipher only supports the following two operation modes: Cipher.WRAP_MODE, and Cipher.UNWRAP_MODE.

For modes other than the above two, UnsupportedOperationException will be thrown.

Parameters
opmode the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.
key the secret key.
params the algorithm parameters; must be null for this cipher.
random the source of randomness.
Throws
InvalidKeyException if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException if the given algorithm parameters is not null.

protected void engineSetMode (String mode)

Sets the mode of this cipher. Only "ECB" mode is accepted for this cipher.

Parameters
mode the cipher mode
Throws
NoSuchAlgorithmException if the requested cipher mode is not "ECB".

protected void engineSetPadding (String padding)

Sets the padding mechanism of this cipher. Only "NoPadding" schmem is accepted for this cipher.

Parameters
padding the padding mechanism
Throws
NoSuchPaddingException if the requested padding mechanism is not "NoPadding".

protected Key engineUnwrap (byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType)

Unwrap a previously wrapped key.

Parameters
wrappedKey the key to be unwrapped.
wrappedKeyAlgorithm the algorithm the wrapped key is for.
wrappedKeyType the type of the wrapped key. This is one of Cipher.SECRET_KEY, Cipher.PRIVATE_KEY, or Cipher.PUBLIC_KEY.
Returns
  • the unwrapped key.
Throws
NoSuchAlgorithmException if no installed providers can create keys of type wrappedKeyType for the wrappedKeyAlgorithm.
InvalidKeyException if wrappedKey does not represent a wrapped key of type wrappedKeyType for the wrappedKeyAlgorithm.

protected int engineUpdate (byte[] in, int inOffset, int inLen, byte[] out, int outOffset)

This operation is not supported by this cipher. Since it's impossible to initialize this cipher given the current Cipher.engineInit(...) implementation, IllegalStateException will always be thrown upon invocation.

Parameters
in the input buffer.
inOffset the offset in in where the input starts.
inLen the input length.
out the buffer for the result.
outOffset the offset in out where the result is stored.
Returns
  • n/a.
Throws
IllegalStateException upon invocation of this method.
ShortBufferException

protected byte[] engineUpdate (byte[] in, int inOffset, int inLen)

This operation is not supported by this cipher. Since it's impossible to initialize this cipher given the current Cipher.engineInit(...) implementation, IllegalStateException will always be thrown upon invocation.

Parameters
in the input buffer.
inOffset the offset in in where the input starts.
inLen the input length.
Returns
  • n/a.
Throws
IllegalStateException upon invocation of this method.

protected byte[] engineWrap (Key key)

Wrap a key.

Parameters
key the key to be wrapped.
Returns
  • the wrapped key.
Throws
IllegalBlockSizeException if this cipher is a block cipher, no padding has been requested, and the length of the encoding of the key to be wrapped is not a multiple of the block size.
InvalidKeyException if it is impossible or unsafe to wrap the key with this cipher (e.g., a hardware protected key is being passed to a software only cipher).