FileDocCategorySizeDatePackage
DESedeKeyGenerator.javaAPI DocAzureus 3.0.3.41641Tue Jun 08 05:12:58 BST 2004org.bouncycastle.crypto.generators

DESedeKeyGenerator

public class DESedeKeyGenerator extends DESKeyGenerator

Fields Summary
Constructors Summary
Methods Summary
public byte[]generateKey()

        byte[]  newKey = new byte[strength];

        do
        {
            random.nextBytes(newKey);

            DESedeParameters.setOddParity(newKey);
        }
        while (DESedeParameters.isWeakKey(newKey, 0, newKey.length));

        return newKey;
    
public voidinit(org.bouncycastle.crypto.KeyGenerationParameters param)
initialise the key generator - if strength is set to zero the key generated will be 192 bits in size, otherwise strength can be 128 or 192 (or 112 or 168 if you don't count parity bits), depending on whether you wish to do 2-key or 3-key triple DES.

param
param the parameters to be used for key generation

        super.init(param);

        if (strength == 0 || strength == (168 / 8))
        {
            strength = DESedeParameters.DES_EDE_KEY_LENGTH;
        }
        else if (strength == (112 / 8))
        {
            strength = 2 * DESedeParameters.DES_KEY_LENGTH;
        }
        else if (strength != DESedeParameters.DES_EDE_KEY_LENGTH
                && strength != (2 * DESedeParameters.DES_KEY_LENGTH))
        {
            throw new IllegalArgumentException("DESede key must be "
                + (DESedeParameters.DES_EDE_KEY_LENGTH * 8) + " or "
                + (2 * 8 * DESedeParameters.DES_KEY_LENGTH)
                + " bits long.");
        }