APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.crypto.provider

public final Class DESedeWrapCipher

extends CipherSpi
Class Inheritance
Imports
java.security.*, java.security.spec.*, java.util.Arrays, javax.crypto.*, javax.crypto.spec.*

This class implements the CMS DESede KeyWrap algorithm as defined in "XML Encryption Syntax and Processing" section 5.6.2 "CMS Triple DES Key Wrap".

Note

only CBC mode and NoPadding padding scheme can be used for this algorithm.

Author
Valerie Peng
See Also
DESedeCipher

Field Summary

Modifier and TypeField and Description
private static final int
private final FeedbackCipher
private Key
private boolean
private byte[]
private static final byte[]
private static final int

Constructor Summary

AccessConstructor and Description
public
DESedeWrapCipher()

Creates an instance of CMS DESede KeyWrap cipher with default mode, i.e. "CBC" and padding scheme, i.e. "NoPadding".

Method Summary

Modifier and TypeMethod and Description
protected byte[]

Returns:

the new buffer with the result.
engineDoFinal
(byte[]
the input buffer.
in
,
int
the offset in in where the input starts.
inOffset
,
int
the input length.
inLen
)

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

This operation is not supported by this cipher.

protected int

Returns:

the number of bytes stored in out.
engineDoFinal
(byte[]
the input buffer.
input
,
int
the offset in input where the input starts.
inputOffset
,
int
the input length.
inputLen
,
byte[]
the buffer for the result.
output
,
int
the ofset in output where the result is stored.
outputOffset
)

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

This operation is not supported by this cipher.

protected int

Returns:

the block size (in bytes), i.e. 8 bytes.
engineGetBlockSize
()

Implements abstract javax.crypto.CipherSpi.engineGetBlockSize.

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

protected byte[]

Returns:

the initialization vector, or null if the underlying algorithm does not use an IV, or if the IV has not yet been set.
engineGetIV
()

Implements abstract javax.crypto.CipherSpi.engineGetIV.

Returns the initialization vector (IV) in a new buffer.

protected int

Returns:

the "effective" key size of the given key object.
engineGetKeySize
(Key
the key object.
key
)

Overrides javax.crypto.CipherSpi.engineGetKeySize.

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

protected int

Returns:

the required output buffer size (in bytes).
engineGetOutputSize
(int
the input length (in bytes).
inputLen
)

Implements abstract javax.crypto.CipherSpi.engineGetOutputSize.

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

protected AlgorithmParameters

Returns:

the parameters used with this cipher; can be null.
engineGetParameters
()

Implements abstract javax.crypto.CipherSpi.engineGetParameters.

Returns the parameters used with this cipher.

protected void
engineInit(int
the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.
opmode
,
Key
the secret key.
key
,
SecureRandom
the source of randomness.
random
)

Implements abstract javax.crypto.CipherSpi.engineInit.

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

protected void
engineInit(int
the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.
opmode
,
Key
the secret key.
key
,
AlgorithmParameterSpec
the algorithm parameters.
params
,
SecureRandom
the source of randomness.
random
)

Implements abstract javax.crypto.CipherSpi.engineInit.

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

protected void
engineInit(int
the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.
opmode
,
Key
the secret key.
key
,
AlgorithmParameters
the algorithm parameters.
params
,
SecureRandom
the source of randomness.
random
)

Implements abstract javax.crypto.CipherSpi.engineInit.

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

protected void
engineSetMode(String
the cipher mode.
mode
)

Implements abstract javax.crypto.CipherSpi.engineSetMode.

Sets the mode of this cipher.

protected void
engineSetPadding(String
the padding mechanism.
padding
)

Implements abstract javax.crypto.CipherSpi.engineSetPadding.

Sets the padding mechanism of this cipher.

protected Key

Returns:

the unwrapped key.
engineUnwrap
(byte[]
the key to be unwrapped.
wrappedKey
,
String
the algorithm the wrapped key is for.
wrappedKeyAlgorithm
,
int
the type of the wrapped key. This is one of Cipher.SECRET_KEY, Cipher.PRIVATE_KEY, or Cipher.PUBLIC_KEY.
wrappedKeyType
)

Overrides javax.crypto.CipherSpi.engineUnwrap.

Unwrap a previously wrapped key.

protected byte[]

Returns:

n/a.
engineUpdate
(byte[]
the input buffer.
in
,
int
the offset in in where the input starts.
inOffset
,
int
the input length.
inLen
)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

This operation is not supported by this cipher.

protected int

Returns:

n/a.
engineUpdate
(byte[]
the input buffer.
in
,
int
the offset in in where the input starts.
inOffset
,
int
the input length.
inLen
,
byte[]
the buffer for the result.
out
,
int
the offset in out where the result is stored.
outOffset
)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

This operation is not supported by this cipher.

protected byte[]

Returns:

the wrapped key.
engineWrap
(Key
the key to be wrapped.
key
)

Overrides javax.crypto.CipherSpi.engineWrap.

Wrap a key.

private static final byte[]
getChecksum(byte[] in)

private static final byte[]
getChecksum(byte[] in, int offset, int len)

Inherited from javax.crypto.CipherSpi:
engineDoFinalengineUpdateengineUpdateAADengineUpdateAAD

Field Detail

CHECKSUM_LENback to summary
private static final int CHECKSUM_LEN
cipherback to summary
private final FeedbackCipher cipher
cipherKeyback to summary
private Key cipherKey
decryptingback to summary
private boolean decrypting
ivback to summary
private byte[] iv
IV2back to summary
private static final byte[] IV2
IV_LENback to summary
private static final int IV_LEN

Constructor Detail

DESedeWrapCipherback to summary
public DESedeWrapCipher()

Creates an instance of CMS DESede KeyWrap cipher with default mode, i.e. "CBC" and padding scheme, i.e. "NoPadding".

Method Detail

engineDoFinalback to summary
protected byte[] engineDoFinal(byte[] in, int inOffset, int inLen) throws IllegalBlockSizeException, BadPaddingException

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

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:byte[]

the input buffer.

inOffset:int

the offset in in where the input starts.

inLen:int

the input length.

Returns:byte[]

the new buffer with the result.

Exceptions
IllegalBlockSizeException:

Doc from javax.crypto.CipherSpi.engineDoFinal.

if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided

BadPaddingException:

Doc from javax.crypto.CipherSpi.engineDoFinal.

if this CipherSpi object is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes

IllegalStateException:
upon invocation of this method.
engineDoFinalback to summary
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, ShortBufferException, BadPaddingException

Implements abstract javax.crypto.CipherSpi.engineDoFinal.

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:byte[]

the input buffer.

inputOffset:int

the offset in input where the input starts.

inputLen:int

the input length.

output:byte[]

the buffer for the result.

outputOffset:int

the ofset in output where the result is stored.

Returns:int

the number of bytes stored in out.

Exceptions
IllegalBlockSizeException:

Doc from javax.crypto.CipherSpi.engineDoFinal.

if this cipher is a block cipher, no padding has been requested (only in encryption mode), and the total input length of the data processed by this cipher is not a multiple of block size; or if this encryption algorithm is unable to process the input data provided

ShortBufferException:

Doc from javax.crypto.CipherSpi.engineDoFinal.

if the given output buffer is too small to hold the result

BadPaddingException:

Doc from javax.crypto.CipherSpi.engineDoFinal.

if this CipherSpi object is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes

IllegalStateException:
upon invocation of this method.
engineGetBlockSizeback to summary
protected int engineGetBlockSize()

Implements abstract javax.crypto.CipherSpi.engineGetBlockSize.

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

Returns:int

the block size (in bytes), i.e. 8 bytes.

engineGetIVback to summary
protected byte[] engineGetIV()

Implements abstract javax.crypto.CipherSpi.engineGetIV.

Returns the initialization vector (IV) in a new buffer.

Returns:byte[]

the initialization vector, or null if the underlying algorithm does not use an IV, or if the IV has not yet been set.

engineGetKeySizeback to summary
protected int engineGetKeySize(Key key) throws InvalidKeyException

Overrides javax.crypto.CipherSpi.engineGetKeySize.

Returns the key size of the given key object in number of bits. This cipher always return the same key size as the DESede ciphers.

Parameters
key:Key

the key object.

Returns:int

the "effective" key size of the given key object.

Exceptions
InvalidKeyException:
if key is invalid.
engineGetOutputSizeback to summary
protected int engineGetOutputSize(int inputLen)

Implements abstract javax.crypto.CipherSpi.engineGetOutputSize.

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:int

the input length (in bytes).

Returns:int

the required output buffer size (in bytes).

engineGetParametersback to summary
protected AlgorithmParameters engineGetParameters()

Implements abstract javax.crypto.CipherSpi.engineGetParameters.

Returns the parameters used with this cipher. Note that null maybe returned if this cipher does not use any parameters or when it has not been set, e.g. initialized with UNWRAP_MODE but wrapped key data has not been given.

Returns:AlgorithmParameters

the parameters used with this cipher; can be null.

engineInitback to summary
protected void engineInit(int opmode, Key key, SecureRandom random) throws InvalidKeyException

Implements abstract javax.crypto.CipherSpi.engineInit.

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.

If this cipher requires an initialization vector (IV), it will get it from random.

Parameters
opmode:int

the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.

key:Key

the secret key.

random:SecureRandom

the source of randomness.

Exceptions
InvalidKeyException:
if the given key is inappropriate or if parameters are required but not supplied.
engineInitback to summary
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.CipherSpi.engineInit.

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.

If this cipher requires an initialization vector (IV), it will get it from random.

Parameters
opmode:int

the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.

key:Key

the secret key.

params:AlgorithmParameterSpec

the algorithm parameters.

random:SecureRandom

the source of randomness.

Exceptions
InvalidKeyException:
if the given key is inappropriate.
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher.
engineInitback to summary
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Implements abstract javax.crypto.CipherSpi.engineInit.

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.

If this cipher requires an initialization vector (IV), it will get it from random.

Parameters
opmode:int

the operation mode of this cipher. Only WRAP_MODE or UNWRAP_MODE) are accepted.

key:Key

the secret key.

params:AlgorithmParameters

the algorithm parameters.

random:SecureRandom

the source of randomness.

Exceptions
InvalidKeyException:
if the given key is inappropriate.
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher.
engineSetModeback to summary
protected void engineSetMode(String mode) throws NoSuchAlgorithmException

Implements abstract javax.crypto.CipherSpi.engineSetMode.

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

Parameters
mode:String

the cipher mode.

Exceptions
NoSuchAlgorithmException:
if the requested cipher mode is not "CBC".
engineSetPaddingback to summary
protected void engineSetPadding(String padding) throws NoSuchPaddingException

Implements abstract javax.crypto.CipherSpi.engineSetPadding.

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

Parameters
padding:String

the padding mechanism.

Exceptions
NoSuchPaddingException:
if the requested padding mechanism is not "NoPadding".
engineUnwrapback to summary
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException

Overrides javax.crypto.CipherSpi.engineUnwrap.

Unwrap a previously wrapped key.

Parameters
wrappedKey:byte[]

the key to be unwrapped.

wrappedKeyAlgorithm:String

the algorithm the wrapped key is for.

wrappedKeyType:int

the type of the wrapped key. This is one of Cipher.SECRET_KEY, Cipher.PRIVATE_KEY, or Cipher.PUBLIC_KEY.

Returns:Key

the unwrapped key.

Exceptions
InvalidKeyException:
if wrappedKey does not represent a wrapped key of type wrappedKeyType for the wrappedKeyAlgorithm.
NoSuchAlgorithmException:
if no installed providers can create keys of type wrappedKeyType for the wrappedKeyAlgorithm.
engineUpdateback to summary
protected byte[] engineUpdate(byte[] in, int inOffset, int inLen)

Implements abstract javax.crypto.CipherSpi.engineUpdate.

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:byte[]

the input buffer.

inOffset:int

the offset in in where the input starts.

inLen:int

the input length.

Returns:byte[]

n/a.

Exceptions
IllegalStateException:
upon invocation of this method.
engineUpdateback to summary
protected int engineUpdate(byte[] in, int inOffset, int inLen, byte[] out, int outOffset) throws ShortBufferException

Implements abstract javax.crypto.CipherSpi.engineUpdate.

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:byte[]

the input buffer.

inOffset:int

the offset in in where the input starts.

inLen:int

the input length.

out:byte[]

the buffer for the result.

outOffset:int

the offset in out where the result is stored.

Returns:int

n/a.

Exceptions
ShortBufferException:

Doc from javax.crypto.CipherSpi.engineUpdate.

if the given output buffer is too small to hold the result

IllegalStateException:
upon invocation of this method.
engineWrapback to summary
protected byte[] engineWrap(Key key) throws IllegalBlockSizeException, InvalidKeyException

Overrides javax.crypto.CipherSpi.engineWrap.

Wrap a key.

Parameters
key:Key

the key to be wrapped.

Returns:byte[]

the wrapped key.

Exceptions
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).
getChecksumback to summary
private static final byte[] getChecksum(byte[] in)
getChecksumback to summary
private static final byte[] getChecksum(byte[] in, int offset, int len)