ECB
, CFB
, OFB
, CBC
,
PCBC
) and padding schemes (PKCS5Padding
,
NoPadding
). DES hardware support is for the CBC
mode only. All other modes will use software.
In addition, the system property ibm.DES.usehdwr.size
value
determines whether hardware or software is used for the CBC
mode. If the size of the data to be encrypted/decrypted
is greater than the value of ibm.DES.usehdwr.size
, then
hardware is used. Otherwise, software is used. When the value of
ibm.DES.usehdwr.size
is -1, software is always used.
When the value of ibm.DES.usehdwr.size
is 0, hardware is used
if it supports the specified mode.
This documentation describes a Service Provider Interface. It is provided for implementation insight only. This class is not intended to be called directly by application developers. Please consult the 'Java Cryptography Architecture Standard' for details on how to use this interface through a public standard class.
- NOTE:
- Certain operations may require specific hardware or software, or specific key types. See the rest of this document and the z/OS Unique Considerations Hardware Crypto Reference Guide for more details. Unsupported operations and/or combinations may result in a RuntimeException Hardware Error.
javax.crypto.Cipher
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
CBC mode encryption.protected static final int
CFB mode encryption.protected int
The cipher mode.static final int
Default DES block size in number of bytes.protected static final int
ECB mode encryption.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.protected static final int
OFB mode encryption.protected static final int
PCBC mode encryption.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.protected com.ibm.crypto.hdwrCCA.provider.DESCrypt
The (raw) algorithm.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only.static final int[]
Intended for internal use only. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
engineDoFinal
(byte[] input, int inputOffset, int inputLen) Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.protected int
engineDoFinal
(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.protected int
Returns the block size (in bytes).protected byte[]
Returns the initialization vector (IV) in a new buffer.protected int
engineGetKeySize
(Key key) Returns the key size of the given key object.protected int
engineGetOutputSize
(int inputLen) Returns the length in bytes that an output buffer would need to be in order to hold the result of the nextupdate
ordoFinal
operation, given the input lengthinputLen
(in bytes).protected AlgorithmParameters
Returns the parameters used with this cipher.protected void
engineInit
(int opmode, Key key, AlgorithmParameters params, SecureRandom random) Initializes this cipher with an operation mode, a key, a set of algorithm parameters, and a source of randomness.protected void
engineInit
(int opmode, Key key, SecureRandom random) Initializes this cipher with an operation mode, a key and a source of randomness.protected void
engineInit
(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) Initializes this cipher with an operation mode, a key, a set of algorithm parameters, and a source of randomness.protected void
engineSetMode
(String mode) Sets the mode of this cipher.protected void
engineSetPadding
(String paddingScheme) Sets the padding mechanism of this cipher.protected Key
engineUnwrap
(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) Unwrap a previously wrapped key.protected byte[]
engineUpdate
(byte[] input, int inputOffset, int inputLen) Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.protected int
engineUpdate
(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.protected byte[]
engineWrap
(Key key) Wrap a key.protected void
Sets the raw algorithm to DES.Methods inherited from class javax.crypto.CipherSpi
engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
-
Field Details
-
cipherMode
protected int cipherModeThe cipher mode. One of ECB, CBC, PCBC, CFB, CFBnn, OFB, or OFBnn. -
ECB_MODE
protected static final int ECB_MODEECB mode encryption. ECB mode encryption can be performed with CLEAR keys (also known as RAW keys), and with CKDS keys for clear and encrypted keys (also known as CKDSLabel keys).- See Also:
-
CBC_MODE
protected static final int CBC_MODECBC mode encryption. CBC mode encryption can be performed with CLEAR keys (also known as RAW keys), with CKDS keys for clear and encrypted keys (also known as CKDSLabel keys), and with SECURE_INTERNAL_TOKEN keys (also known as ICSFToken keys).- See Also:
-
CFB_MODE
protected static final int CFB_MODECFB mode encryption. CFB mode encryption can be performed with CLEAR keys (also known as RAW keys) and with CKDS keys for clear and encrypted keys (also known as CKDSLabel keys). LCFB (specified as CFBnn) encryption can be performed with CLEAR keys (also known as RAW keys).- See Also:
-
OFB_MODE
protected static final int OFB_MODEOFB mode encryption. OFB mode encryption can be performed with CLEAR keys (also known as RAW keys). LOFB (specified as OFBnn) can be performed with CLEAR keys (also known as RAW keys).- See Also:
-
PCBC_MODE
protected static final int PCBC_MODEPCBC mode encryption. PCBC mode encryption can be performed with CLEAR keys (also known as RAW keys).- See Also:
-
rawAlg
protected com.ibm.crypto.hdwrCCA.provider.DESCrypt rawAlgThe (raw) algorithm. This is the implementation of the raw DES or triple-DES algorithm, which can be plugged (viasetEmbeddedCipher
) into one of the cipher mode classesCipherBlockChaining
,CipherFeedback
,ElectronicCodeBook
, orOutputFeedback
. -
DES_BLOCK_SIZE
static final int DES_BLOCK_SIZEDefault DES block size in number of bytes.- See Also:
-
s0p
static final int[] s0pIntended for internal use only. -
s1p
static final int[] s1pIntended for internal use only. -
s2p
static final int[] s2pIntended for internal use only. -
s3p
static final int[] s3pIntended for internal use only. -
s4p
static final int[] s4pIntended for internal use only. -
s5p
static final int[] s5pIntended for internal use only. -
s6p
static final int[] s6pIntended for internal use only. -
s7p
static final int[] s7pIntended for internal use only. -
permRight0
static final int[] permRight0Intended for internal use only. -
permLeft1
static final int[] permLeft1Intended for internal use only. -
permRight2
static final int[] permRight2Intended for internal use only. -
permLeft3
static final int[] permLeft3Intended for internal use only. -
permRight4
static final int[] permRight4Intended for internal use only. -
permLeft5
static final int[] permLeft5Intended for internal use only. -
permRight6
static final int[] permRight6Intended for internal use only. -
permLeft7
static final int[] permLeft7Intended for internal use only. -
permRight8
static final int[] permRight8Intended for internal use only. -
permLeft9
static final int[] permLeft9Intended for internal use only. -
permRightA
static final int[] permRightAIntended for internal use only. -
permLeftB
static final int[] permLeftBIntended for internal use only. -
permRightC
static final int[] permRightCIntended for internal use only. -
permLeftD
static final int[] permLeftDIntended for internal use only. -
permRightE
static final int[] permRightEIntended for internal use only. -
permLeftF
static final int[] permLeftFIntended for internal use only. -
initPermLeft0
static final int[] initPermLeft0Intended for internal use only. -
initPermRight0
static final int[] initPermRight0Intended for internal use only. -
initPermLeft1
static final int[] initPermLeft1Intended for internal use only. -
initPermRight1
static final int[] initPermRight1Intended for internal use only. -
initPermLeft2
static final int[] initPermLeft2Intended for internal use only. -
initPermRight2
static final int[] initPermRight2Intended for internal use only. -
initPermLeft3
static final int[] initPermLeft3Intended for internal use only. -
initPermRight3
static final int[] initPermRight3Intended for internal use only. -
initPermLeft4
static final int[] initPermLeft4Intended for internal use only. -
initPermRight4
static final int[] initPermRight4Intended for internal use only. -
initPermLeft5
static final int[] initPermLeft5Intended for internal use only. -
initPermRight5
static final int[] initPermRight5Intended for internal use only. -
initPermLeft6
static final int[] initPermLeft6Intended for internal use only. -
initPermRight6
static final int[] initPermRight6Intended for internal use only. -
initPermLeft7
static final int[] initPermLeft7Intended for internal use only. -
initPermRight7
static final int[] initPermRight7Intended for internal use only. -
initPermLeft8
static final int[] initPermLeft8Intended for internal use only. -
initPermRight8
static final int[] initPermRight8Intended for internal use only. -
initPermLeft9
static final int[] initPermLeft9Intended for internal use only. -
initPermRight9
static final int[] initPermRight9Intended for internal use only. -
initPermLeftA
static final int[] initPermLeftAIntended for internal use only. -
initPermRightA
static final int[] initPermRightAIntended for internal use only. -
initPermLeftB
static final int[] initPermLeftBIntended for internal use only. -
initPermRightB
static final int[] initPermRightBIntended for internal use only. -
initPermLeftC
static final int[] initPermLeftCIntended for internal use only. -
initPermRightC
static final int[] initPermRightCIntended for internal use only. -
initPermLeftD
static final int[] initPermLeftDIntended for internal use only. -
initPermRightD
static final int[] initPermRightDIntended for internal use only. -
initPermLeftE
static final int[] initPermLeftEIntended for internal use only. -
initPermRightE
static final int[] initPermRightEIntended for internal use only. -
initPermLeftF
static final int[] initPermLeftFIntended for internal use only. -
initPermRightF
static final int[] initPermRightFIntended for internal use only.
-
-
Constructor Details
-
DESCipher
Creates an instance of DES cipher with default ECB mode and PKCS5Padding.- NOTE:
- The mode chosen may not support all key types. See the Field Summary mode documentation and the z/OS Unique Considerations Hardware Crypto Reference Guide for more information.
- Throws:
SecurityException
- if this constructor fails to authenticate the JCE framework.NoSuchAlgorithmException
NoSuchPaddingException
-
DESCipher
public DESCipher(String mode, String paddingScheme) throws NoSuchAlgorithmException, NoSuchPaddingException Creates an instance of DES cipher with the requested mode and padding.- NOTE:
- The mode chosen may not support all key types. See the Field Summary mode documentation and the z/OS Unique Considerations Hardware Crypto Reference Guide for more information.
- Parameters:
mode
- the cipher modepaddingScheme
- the padding mechanism- Throws:
NoSuchAlgorithmException
- if the required cipher mode is unavailable.NoSuchPaddingException
- if the required padding mechanism is unavailable.SecurityException
- if this constructor fails to authenticate the JCE framework.
-
-
Method Details
-
setRawAlg
protected void setRawAlg()Sets the raw algorithm to DES. This method is not a supported customer interface. -
engineSetMode
Sets the mode of this cipher. This method is not a supported customer interface.- Specified by:
engineSetMode
in classCipherSpi
- Parameters:
mode
- the cipher mode- Throws:
NoSuchAlgorithmException
- if the requested cipher mode does not exist.
-
engineSetPadding
Sets the padding mechanism of this cipher. This method is not a supported customer interface.- Specified by:
engineSetPadding
in classCipherSpi
- Parameters:
paddingScheme
- the padding mechanism- Throws:
NoSuchPaddingException
- if the requested padding mechanism does not exist.
-
engineGetBlockSize
protected int engineGetBlockSize()Returns the block size (in bytes).- Specified by:
engineGetBlockSize
in classCipherSpi
- Returns:
- the block size (in bytes) or 0 if the underlying algorithm is not a block cipher.
-
engineGetOutputSize
protected int engineGetOutputSize(int inputLen) Returns the length in bytes that an output buffer would need to be in order to hold the result of the nextupdate
ordoFinal
operation, given the input lengthinputLen
(in bytes).This call takes into account any unprocessed (buffered) data from a previous
update
call, and padding.The actual output length of the next
update
ordoFinal
call may be smaller than the length returned by this method.- Specified by:
engineGetOutputSize
in classCipherSpi
- Parameters:
inputLen
- the input length (in bytes)- Returns:
- the required output buffer size (in bytes).
-
engineGetIV
protected byte[] engineGetIV()Returns the initialization vector (IV) in a new buffer.This is useful in the case where a random IV has been created (see
engineInit(int, Key, SecureRandom)
), or in the context of password-based encryption or decryption, where the IV is derived from a user-provided password.- Specified by:
engineGetIV
in classCipherSpi
- Returns:
- the initialization vector in a new buffer, or null if the underlying algorithm does not use an IV, or if the IV has not yet been set.
-
engineGetParameters
Returns the parameters used with this cipher.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).
- Specified by:
engineGetParameters
in classCipherSpi
- Returns:
- the parameters used with this cipher, or null if this cipher does not use any parameters.
-
engineInit
Initializes this cipher with an operation mode, a key and a source of randomness.The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of
opmode
.If this cipher requires an initialization vector (IV), it will get it from
random
. This behaviour should only be used in encryption or key wrapping mode, however. When initializing a cipher that requires an IV for decryption or key unwrapping, the IV (same IV that was used for encryption or key wrapping) must be provided explicitly as a parameter, in order to get the correct result.This method also cleans existing buffer and other related state information.
- Specified by:
engineInit
in classCipherSpi
- Parameters:
opmode
- the operation mode of this cipher (this is one of the following:ENCRYPT_MODE
,DECRYPT_MODE
,WRAP_MODE
orUNWRAP_MODE
)key
- the secret keyrandom
- the source of randomness- Throws:
InvalidKeyException
- if the given key is inappropriate for initializing this cipher
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException Initializes this cipher with an operation mode, a key, a set of algorithm parameters, and a source of randomness.The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of
opmode
.If this cipher (including its underlying feedback or padding scheme) requires any random bytes, it will get them from
random
.- Specified by:
engineInit
in classCipherSpi
- Parameters:
opmode
- the operation mode of this cipher (this is one of the following:ENCRYPT_MODE
,DECRYPT_MODE
,WRAP_MODE
orUNWRAP_MODE
)key
- the encryption keyparams
- the algorithm parameter specificationrandom
- the source of randomness- Throws:
InvalidKeyException
- if the given key is inappropriate for initializing this cipher.InvalidAlgorithmParameterException
- if the given algorithm parameters are inappropriate for this cipher.
-
engineInit
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException Initializes this cipher with an operation mode, a key, a set of algorithm parameters, and a source of randomness.The cipher is initialized for one of the following four operations: encryption, decryption, key wrapping or key unwrapping, depending on the value of
opmode
.If this cipher (including its underlying feedback or padding scheme) requires any random bytes, it will get them from
random
.- Specified by:
engineInit
in classCipherSpi
- Parameters:
opmode
- the operation mode of this cipher (this is one of the following:ENCRYPT_MODE
,DECRYPT_MODE
,WRAP_MODE
orUNWRAP_MODE
)key
- the encryption keyparams
- the algorithm parametersrandom
- the source of randomness- Throws:
InvalidKeyException
- if the given key is inappropriate for initializing this cipher.InvalidAlgorithmParameterException
- if the given algorithm parameters are inappropriate for this cipher.
-
engineUpdate
protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.The first
inputLen
bytes in theinput
buffer, starting atinputOffset
, are processed, and the result is stored in a new buffer.- Specified by:
engineUpdate
in classCipherSpi
- Parameters:
input
- the input bufferinputOffset
- the offset ininput
where the input startsinputLen
- the input length- Returns:
- the new buffer with the result
-
engineUpdate
protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.The first
inputLen
bytes in theinput
buffer, starting atinputOffset
, are processed, and the result is stored in theoutput
buffer, starting atoutputOffset
.- Specified by:
engineUpdate
in classCipherSpi
- Parameters:
input
- the input bufferinputOffset
- the offset ininput
where the input startsinputLen
- the input lengthoutput
- the buffer for the resultoutputOffset
- the offset inoutput
where the result is stored- Returns:
- the number of bytes stored in
output
. - Throws:
ShortBufferException
- if the given output buffer is too small to hold the result.
-
engineDoFinal
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialized.The first
inputLen
bytes in theinput
buffer, starting atinputOffset
, and any input bytes that may have been buffered during a previousupdate
operation, are processed, with padding (if requested) being applied. The result is stored in a new buffer.The cipher is reset to its initial state (uninitialized) after this call.
- Specified by:
engineDoFinal
in classCipherSpi
- Parameters:
input
- the input bufferinputOffset
- the offset ininput
where the input startsinputLen
- the input length- Returns:
- the new buffer with the result.
- Throws:
IllegalBlockSizeException
- 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.BadPaddingException
- if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes.
-
engineDoFinal
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, ShortBufferException, BadPaddingException Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialized.The first
inputLen
bytes in theinput
buffer, starting atinputOffset
, and any input bytes that may have been buffered during a previousupdate
operation, are processed, with padding (if requested) being applied. The result is stored in theoutput
buffer, starting atoutputOffset
.The cipher is reset to its initial state (uninitialized) after this call.
- Specified by:
engineDoFinal
in classCipherSpi
- Parameters:
input
- the input bufferinputOffset
- the offset ininput
where the input startsinputLen
- the input lengthoutput
- the buffer for the resultoutputOffset
- the offset inoutput
where the result is stored- Returns:
- the number of bytes stored in
output
. - Throws:
IllegalBlockSizeException
- 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.ShortBufferException
- if the given output buffer is too small to hold the result.BadPaddingException
- if this cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes.
-
engineGetKeySize
Returns the key size of the given key object.This method is called by the JCE framework to ensure that the size of the key to be used does not exceed the maximum allowable key size specified in the Java restricted policy files.
Cipher operations done at the hardware level should bypass the Java restricted policy files check because the cryptographic hardware enforces the US export restrictions relating to cryptographic keys.
If a hardware key is used for a DES or DESede cipher operation, we can bypass the restricted policy files checking by returning a key size that conforms to the policy files.
If a clear key in RAW format is used for a DES or DESede cipher operation, the operation may or may not be done at the hardware level. The operation may be passed to the IBMJCE software cryptographic implementation. Since the software implementation does not enforce US export restrictions, we must return the correct key size in order for JCE framework to enforce the Java restricted policy files.
- Overrides:
engineGetKeySize
in classCipherSpi
- Parameters:
key
- the key object.- Returns:
- the actual key size if the key is in RAW format. Otherwise, a key size that will pass the restricted policy files check done by the JCE framework.
-
engineWrap
Wrap a key.- Overrides:
engineWrap
in classCipherSpi
- Parameters:
key
- the key to be wrapped. This key must be aRAW
Cipher.SECRET_KEY
. This cipher does not support wrapping secret keys of typeICSFToken
or typeCKDSLabel
, and does not support wrappingCipher.PRIVATE_KEY
orCipher.PUBLIC_KEY
.- 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 any of the following is true:- it is impossible or unsafe to wrap the key with this cipher (for example, a hardware protected key is being passed to a software only cipher)
- the key is a
Cipher.PRIVATE_KEY
- the key is a
Cipher.PUBLIC_KEY
- the key is a
Cipher.SECRET_KEY
but is not typeRAW
key
-
engineUnwrap
protected Key engineUnwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException Unwrap a previously wrapped key.- Overrides:
engineUnwrap
in classCipherSpi
- Parameters:
wrappedKey
- the key to be unwrappedwrappedKeyAlgorithm
- the algorithm the wrapped key is forwrappedKeyType
- the type of the wrapped key. This must beCipher.SECRET_KEY
. This cipher does not support unwrapping a key of typeCipher.PRIVATE_KEY
orCipher.PUBLIC_KEY
.- Returns:
- the unwrapped key.
- Throws:
InvalidKeyException
- if any of the following is true:wrappedKey
does not represent a wrapped key- the algorithm associated with the wrapped key is different from
wrappedKeyAlgorithm
- its key type is different from
wrappedKeyType
- the wrappedKeyType parameter is not
Cipher.SECRET_KEY
NoSuchAlgorithmException
- if no installed providers can create keys for thewrappedKeyAlgorithm
.
-