public class DESKeyGenerator
extends javax.crypto.KeyGeneratorSpi
An application uses
KeyGenerator des_key_gen =
KeyGenerator.getInstance("DES"); for creating a
KeyGenerator object for the DES algorithm. For actually generating the
requested secret DES key from the KeyGenerator object just created, an
application calls the generateKey method after having initialized
the generator with some random seed or relied on the default system-provided
source of randomness:
SecretKey des_key = des_key_gen.generateKey();
Due to the way, the DES algorithm generates sub-keys for the several DES rounds, some initial keys may be classified as weak or semi-weak keys reducing the security of the DES cipher (see "Applied Cryptography", Bruce Schneier, ISBN 0-471-59756-2). This KeyGenerator class ensures to generate a strong DES key by repeating the key generation process as long as comparison with all the known weak and semi-weak DES keys will show that the just created key is not a strong one.
For ensuring to create a strong DES key, the key generation process is repeated as long as comparison with all the known weak and semi-weak DES keys will show that the just created key is not a strong DES key.
This class SHOULD NOT be used directly; it should only be used through the JCA/JCE.
TDEA)(NIST Special Publication 800-67). TDEA may be
used for the protection of Federal information (except keying option 3 (1-key
Triple-DES)); however, NIST encourages agencies to implement the faster and
stronger algorithm specified by FIPS 197, Advanced Encryption Standard (
AES) instead.| Constructor and Description |
|---|
DESKeyGenerator()
The constructor; creates a new instance of the DES key generation
algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
adjustParity(byte[] key,
int offset)
Adjusts the parity-bits of a DES key, supplied in a byte array beginning
at the given offset.
|
static boolean |
checkParity(byte[] key,
int offset,
boolean odd)
Checks if the given DES key, supplied in a byte array beginning at the
given offset, is parity adjusted.
|
protected javax.crypto.SecretKey |
engineGenerateKey()
Generates a secret key.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes the key generator with the specified parameter set and a
user-provided source of randomness.
|
protected void |
engineInit(int strength,
java.security.SecureRandom random)
Initializes this key generator for a certain keysize, using the given
source of randomness.
|
protected void |
engineInit(java.security.SecureRandom random)
Initializes the key generator.
|
public DESKeyGenerator()
Applications should not use this constructor, instead the key generation
algorithm should be requested from the appropriate JCA/JCE cryptographic
service provider as follows:
KeyGenerator.getInstance("DES", "IAIK").
protected javax.crypto.SecretKey engineGenerateKey()
public static void adjustParity(byte[] key,
int offset)
key - [FIPS 140-2 data input] [FIPS 140-2 CSP] the byte array
holding the DES keyoffset - [FIPS 140-2 data input] the offset indicating where the key
starts within the given byte arrayFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationspublic static boolean checkParity(byte[] key,
int offset,
boolean odd)
key - [FIPS 140-2 data input] [FIPS 140-2 CSP] the byte array
holding the DES keyoffset - [FIPS 140-2 data input] the offset indicating where the key
starts within the given byte arrayodd - [FIPS 140-2 control input] whether to check for odd or even
paritytrue if checking for odd
parity and the key is odd parity adjusted; true if
checking for even parity and the key is even parity adjusted;
false in any other case (note that if this method
returns false when checking for odd (even) parity, this does not
necessarily mean that the key is even (odd) parity adjustedFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected void engineInit(java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
throws java.security.InvalidAlgorithmParameterException
engineInit in class javax.crypto.KeyGeneratorSpiparams - [FIPS 140-2 data input] the key generation parametersrandom - [FIPS 140-2 control input] the source of randomness for this
key generatorjava.security.InvalidAlgorithmParameterException - [FIPS 140-2 status output] if params is
inappropriate for this key generatorFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected void engineInit(int strength,
java.security.SecureRandom random)
Lengths outside the range of minimum to maximum length default to the default length.
engineInit in class javax.crypto.KeyGeneratorSpikeysize - [FIPS 140-2 data input] the keysize. This is an
algorithm-specific metric, specified in number of bits.random - [FIPS 140-2 control input] the source of randomness for this
key generatorFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationsprotected void engineInit(java.security.SecureRandom random)
The strength defaults to the default length.
engineInit in class javax.crypto.KeyGeneratorSpirandom - [FIPS 140-2 control input] the source of randomness for this
generatorFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operations