de.flexiprovider.core.pbe
Class PBEWithSHAAnd3_KeyTripleDES_CBC

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--de.flexiprovider.api.Cipher
              |
              +--de.flexiprovider.core.pbe.interfaces.PBES1
                    |
                    +--de.flexiprovider.core.pbe.PBES1
                          |
                          +--de.flexiprovider.core.pbe.PBEWithSHAAnd3_KeyTripleDES_CBC

public class PBEWithSHAAnd3_KeyTripleDES_CBC
extends PBES1

This class implements passphrase based encryption (PBE) as defined in PKCS#12 version 1.2. The key for the cipher (here DES) is derived from the passphrase by applying a hashfunction (here SHA-1) several times on it. Because we don't provide single DES, DESede with the same key for encryption, decryption, encryption is used instead.

Author:
Michele Boivin

Field Summary
static java.lang.String OID
          The OID of PBEWithSHAAnd3_KeyTripleDES_CBC.
 
Fields inherited from class de.flexiprovider.core.pbe.PBES1
cipher, kdf
 
Fields inherited from class de.flexiprovider.api.Cipher
DECRYPT_MODE, ENCRYPT_MODE, opMode
 
Constructor Summary
PBEWithSHAAnd3_KeyTripleDES_CBC()
          The default constructor tries to initialize the message digest, the secret key factory and the cipher.
 
Method Summary
 int getKeySize(Key key)
          Returns the key size of the given key object.
 java.lang.String getName()
           
 void initDecrypt(Key key, AlgorithmParameterSpec params)
          Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
 void initEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom random)
          Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.
 
Methods inherited from class de.flexiprovider.core.pbe.PBES1
doFinal, doFinal, getBlockSize, getIV, getOutputSize, getParameters, setMode, setPadding, update, update
 
Methods inherited from class de.flexiprovider.core.pbe.interfaces.PBES1
engineInit
 
Methods inherited from class de.flexiprovider.api.Cipher
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, update
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OID

public static final java.lang.String OID
The OID of PBEWithSHAAnd3_KeyTripleDES_CBC.
Constructor Detail

PBEWithSHAAnd3_KeyTripleDES_CBC

public PBEWithSHAAnd3_KeyTripleDES_CBC()
The default constructor tries to initialize the message digest, the secret key factory and the cipher.
Method Detail

getName

public java.lang.String getName()
Overrides:
getName in class Cipher
Returns:
the name of this cipher

getKeySize

public int getKeySize(Key key)
               throws InvalidKeyException
Returns the key size of the given key object. Since the cipher underlying this PBE scheme is DES, we always return 112 as the effective key size if the key is valid.
Overrides:
getKeySize in class Cipher
Parameters:
key - the key object
Returns:
the key size of the given key object.
Throws:
InvalidKeyException - if key is not an instance of PBEKey

initEncrypt

public void initEncrypt(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 encryption.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Overrides:
initEncrypt in class Cipher
Parameters:
key - the encryption key
params - the algorithm parameters
random - 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, or if this cipher is being initialized fro decryption and requires algorithm parameters and params is null

initDecrypt

public void initDecrypt(Key key,
                        AlgorithmParameterSpec params)
                 throws InvalidKeyException,
                        InvalidAlgorithmParameterException
Initializes this cipher with a key, a set of algorithm parameters, and a source of randomness.

The cipher is initialized for decryption.

If this cipher requires any algorithm parameters and params is null, the underlying cipher implementation is supposed to generate the required parameters itself (using provider-specific default or random values) if it is being initialized for encryption, and raise an InvalidAlgorithmParameterException if it is being initialized for decryption. The generated parameters can be retrieved using engineGetParameters or engineGetIV (if the parameter is an IV).

If this cipher (including its underlying feedback or padding scheme) requires any random bytes (e.g., for parameter generation), it will get them from random.

Note that when a Cipher object is initialized, it loses all previously-acquired state. In other words, initializing a Cipher is equivalent to creating a new instance of that Cipher and initializing it.

Overrides:
initDecrypt in class Cipher
Parameters:
key - the encryption key
params - the algorithm parameters
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher
InvalidAlgorithmParameterException - if the given algorithm parameters are inappropriate for this cipher, or if this cipher is being initialized fro decryption and requires algorithm parameters and params is null