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

pack-priv final Class PBES1Core

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

This class represents password-based encryption as defined by the PKCS #5 standard.
Author
Jan Luehe
See Also
javax.crypto.Cipher

Field Summary

Modifier and TypeField and Description
private final String
private final CipherCore
private int
private final MessageDigest
private byte[]

Constructor Summary

AccessConstructor and Description
pack-priv
PBES1Core(String cipherAlg)

Creates an instance of PBE Cipher using the specified CipherSpi instance.

Method Summary

Modifier and TypeMethod and Description
private byte[]
deriveCipherKey(byte[] passwdBytes)

pack-priv byte[]

Returns:

the new buffer with the result
doFinal
(byte[]
the input buffer
input
,
int
the offset in input where the input starts
inputOffset
,
int
the input length
inputLen
)

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.

pack-priv int

Returns:

the number of bytes stored in output
doFinal
(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 offset in output where the result is stored
outputOffset
)

Encrypts or decrypts data in a single-part operation, or finishes a multiple-part operation.

private static byte[]
pack-priv int

Returns:

the block size (in bytes)
getBlockSize
()

Returns the block size (in bytes).

pack-priv byte[]

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.
getIV
()

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

pack-priv int

Returns:

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

Returns 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).

pack-priv AlgorithmParameters

Returns:

the parameters used with this cipher, or null if this cipher does not use any parameters.
getParameters
()

Returns the parameters used with this cipher.

pack-priv void
init(int
the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE), WRAP_MODE or UNWRAP_MODE)
opmode
,
Key
the encryption key
key
,
AlgorithmParameterSpec
the algorithm parameters
params
,
SecureRandom
the source of randomness
random
)

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

pack-priv void
init(int opmode, Key key, AlgorithmParameters params, SecureRandom random)

private static boolean
isWeak(byte[] s)

pack-priv void
setMode(String
the cipher mode
mode
)

Sets the mode of this cipher.

pack-priv void
setPadding(String
the padding mechanism
paddingScheme
)

Sets the padding mechanism of this cipher.

pack-priv Key

Returns:

the unwrapped key.
unwrap
(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
)

Unwrap a previously wrapped key.

pack-priv byte[]

Returns:

the new buffer with the result
update
(byte[]
the input buffer
input
,
int
the offset in input where the input starts
inputOffset
,
int
the input length
inputLen
)

Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.

pack-priv int

Returns:

the number of bytes stored in output
update
(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 offset in output where the result is stored
outputOffset
)

Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.

pack-priv byte[]

Returns:

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

Wrap a key.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algoback to summary
private final String algo
cipherback to summary
private final CipherCore cipher
iCountback to summary
private int iCount
mdback to summary
private final MessageDigest md
saltback to summary
private byte[] salt

Constructor Detail

PBES1Coreback to summary
pack-priv PBES1Core(String cipherAlg) throws NoSuchAlgorithmException, NoSuchPaddingException

Creates an instance of PBE Cipher using the specified CipherSpi instance.

Method Detail

deriveCipherKeyback to summary
private byte[] deriveCipherKey(byte[] passwdBytes)
doFinalback to summary
pack-priv byte[] doFinal(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 the input buffer, starting at inputOffset, and any input bytes that may have been buffered during a previous update 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.

Parameters
input:byte[]

the input buffer

inputOffset:int

the offset in input where the input starts

inputLen:int

the input length

Returns:byte[]

the new buffer with the result

Exceptions
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 decrypting and padding is chosen, but the last input data does not have proper padding bytes.
doFinalback to summary
pack-priv int doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException, 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 the input buffer, starting at inputOffset, and any input bytes that may have been buffered during a previous update operation, are processed, with padding (if requested) being applied. The result is stored in the output buffer, starting at outputOffset.

The cipher is reset to its initial state (uninitialized) after this call.

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 offset in output where the result is stored

Returns:int

the number of bytes stored in output

Exceptions
ShortBufferException:
if the given output buffer is too small to hold the result
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 decrypting and padding is chosen, but the last input data does not have proper padding bytes.
generateSaltback to summary
private static byte[] generateSalt(String algo, SecureRandom sr)
getBlockSizeback to summary
pack-priv int getBlockSize()

Returns the block size (in bytes).

Returns:int

the block size (in bytes)

getIVback to summary
pack-priv byte[] getIV()

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

This is useful in the case where a random IV has been created (see init), or in the context of password-based encryption or decryption, where the IV is derived from a user-supplied password.

Returns:byte[]

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.

getOutputSizeback to summary
pack-priv int getOutputSize(int inputLen)

Returns 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).

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.

Parameters
inputLen:int

the input length (in bytes)

Returns:int

the required output buffer size (in bytes)

getParametersback to summary
pack-priv AlgorithmParameters getParameters()

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).

Returns:AlgorithmParameters

the parameters used with this cipher, or null if this cipher does not use any parameters.

initback to summary
pack-priv void init(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException

Initializes this cipher with 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.

Parameters
opmode:int

the operation mode of this cipher (this is one of the following: ENCRYPT_MODE, DECRYPT_MODE), WRAP_MODE or UNWRAP_MODE)

key:Key

the encryption key

params:AlgorithmParameterSpec

the algorithm parameters

random:SecureRandom

the source of randomness

Exceptions
InvalidKeyException:
if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException:
if the given algorithm parameters are inappropriate for this cipher
initback to summary
pack-priv void init(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException
isWeakback to summary
private static boolean isWeak(byte[] s)
setModeback to summary
pack-priv void setMode(String mode) throws NoSuchAlgorithmException

Sets the mode of this cipher. This algorithm can only be run in CBC mode.

Parameters
mode:String

the cipher mode

Exceptions
NoSuchAlgorithmException:
if the requested cipher mode is invalid
setPaddingback to summary
pack-priv void setPadding(String paddingScheme) throws NoSuchPaddingException

Sets the padding mechanism of this cipher. This algorithm only uses PKCS #5 padding.

Parameters
paddingScheme:String

the padding mechanism

Exceptions
NoSuchPaddingException:
if the requested padding mechanism is invalid
unwrapback to summary
pack-priv Key unwrap(byte[] wrappedKey, String wrappedKeyAlgorithm, int wrappedKeyType) throws InvalidKeyException, NoSuchAlgorithmException

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.
updateback to summary
pack-priv byte[] update(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 the input buffer, starting at inputOffset, are processed, and the result is stored in a new buffer.

Parameters
input:byte[]

the input buffer

inputOffset:int

the offset in input where the input starts

inputLen:int

the input length

Returns:byte[]

the new buffer with the result

updateback to summary
pack-priv int update(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 the input buffer, starting at inputOffset, are processed, and the result is stored in the output buffer, starting at outputOffset.

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 offset in output where the result is stored

Returns:int

the number of bytes stored in output

Exceptions
ShortBufferException:
if the given output buffer is too small to hold the result
wrapback to summary
pack-priv byte[] wrap(Key key) throws IllegalBlockSizeException, InvalidKeyException

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).