For the latest news and information visit The GNU Crypto project

## gnu.crypto.cipher
Class DES

    java.lang.Object
      |
      +--gnu.crypto.cipher.BaseCipher
            |
            +--gnu.crypto.cipher.DES

All Implemented Interfaces:
  java.lang.Cloneable, IBlockCipher, gnu.crypto.cipher.IBlockCipherSpi

public class DES
extends BaseCipher

The Data Encryption Standard. DES is a 64-bit block cipher with a 56-bit key, developed by IBM in the 1970's for the standardization process begun by the National Bureau of Standards (now NIST).

New applications should not use DES except for compatibility.

This version is based upon the description and sample implementation in [1].

References:

1. Bruce Schneier, Applied Cryptography: Protocols, Algorithms, and Source Code in C, Second Edition. (1996 John Wiley and Sons) ISBN 0-471-11709-9. Pages 265--301, 623--632.

Field Summary
`static int` `BLOCK_SIZE` DES operates on 64 bit blocks.
`static int` `KEY_SIZE` DES uses 56 bits of a 64 bit parity-adjusted key.
`static byte[][]` `POSSIBLE_WEAK_KEYS` Possible weak keys (parity adjusted) --produce 4 instead of 16 subkeys.
`static byte[][]` `SEMIWEAK_KEYS` Semi-weak keys (parity adjusted): Some pairs of keys encrypt plain text to identical cipher text.
`static byte[][]` `WEAK_KEYS` Weak keys (parity adjusted): If all the bits in each half are either 0 or 1, then the key used for any cycle of the algorithm is the same as all other cycles.

Fields inherited from class gnu.crypto.cipher.BaseCipher
`currentBlockSize, currentKey, defaultBlockSize, defaultKeySize, lock, name`

Fields inherited from interface gnu.crypto.cipher.IBlockCipher
`CIPHER_BLOCK_SIZE, KEY_MATERIAL`

Constructor Summary
`DES()` Default 0-argument constructor.

Method Summary
`static void` `adjustParity(byte[] kb, int offset)` Adjust the parity for a raw key array.
`java.util.Iterator` `blockSizes()` Returns an `Iterator` over the supported block sizes.
`java.lang.Object` `clone()` Returns a clone of this instance.
`void` `decrypt(byte[] in, int i, byte[] out, int o, java.lang.Object K, int bs)` Decrypts exactly one block of ciphertext.
`void` `encrypt(byte[] in, int i, byte[] out, int o, java.lang.Object K, int bs)` Encrypts exactly one block of plaintext.
`static boolean` `isParityAdjusted(byte[] kb, int offset)` Test if a byte array, which must be at least 8 bytes long, is parity adjusted.
`static boolean` `isPossibleWeak(byte[] kb)` Test if the designated byte array represents a possibly weak key.
`static boolean` `isSemiWeak(byte[] kb)` Test if a key is a semi-weak key.
`static boolean` `isWeak(byte[] kb)` Test if a key is a weak key.
`java.util.Iterator` `keySizes()` Returns an `Iterator` over the supported key sizes.
`java.lang.Object` `makeKey(byte[] kb, int bs)` Expands a user-supplied key material into a session key for a designated block size.

Methods inherited from class gnu.crypto.cipher.BaseCipher
`currentBlockSize, decryptBlock, defaultBlockSize, defaultKeySize, encryptBlock, init, name, reset, selfTest, testKat, testKat`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### BLOCK_SIZE

    public static final int BLOCK_SIZE

  DES operates on 64 bit blocks.

  See Also:
    Constant Field Values

### KEY_SIZE

    public static final int KEY_SIZE

  DES uses 56 bits of a 64 bit parity-adjusted key.

  See Also:
    Constant Field Values

### WEAK_KEYS

    public static final byte[][] WEAK_KEYS

  Weak keys (parity adjusted): If all the bits in each half are either 0 or 1, then the key used for any cycle of the algorithm is the same as all other cycles.

### SEMIWEAK_KEYS

    public static final byte[][] SEMIWEAK_KEYS

  Semi-weak keys (parity adjusted): Some pairs of keys encrypt plain text to identical cipher text. In other words, one key in the pair can decrypt messages that were encrypted with the other key. These keys are called semi-weak keys. This occurs because instead of 16 different sub-keys being generated, these semi-weak keys produce only two different sub-keys.

### POSSIBLE_WEAK_KEYS

    public static final byte[][] POSSIBLE_WEAK_KEYS

  Possible weak keys (parity adjusted) --produce 4 instead of 16 subkeys.

Constructor Detail

### DES

    public DES()

  Default 0-argument constructor.

Method Detail

### adjustParity

    public static void adjustParity(byte[] kb,
                                    int offset)

  Adjust the parity for a raw key array. This essentially means that each byte in the array will have an odd number of '1' bits (the last bit in each byte is unused.

  Parameters:
    `kb` - The key array, to be parity-adjusted.
    `offset` - The starting index into the key bytes.

### isParityAdjusted

    public static boolean isParityAdjusted(byte[] kb,
                                           int offset)

  Test if a byte array, which must be at least 8 bytes long, is parity adjusted.

  Parameters:
    `kb` - The key bytes.
    `offset` - The starting index into the key bytes.
  Returns:
    `true` if the first 8 bytes of kb have been parity adjusted. `false` otherwise.

### isWeak

    public static boolean isWeak(byte[] kb)

  Test if a key is a weak key.

  Parameters:
    `kb` - The key to test.
  Returns:
    `true` if the key is weak.

### isSemiWeak

    public static boolean isSemiWeak(byte[] kb)

  Test if a key is a semi-weak key.

  Parameters:
    `kb` - The key to test.
  Returns:
    `true` if this key is semi-weak.

### isPossibleWeak

    public static boolean isPossibleWeak(byte[] kb)

  Test if the designated byte array represents a possibly weak key.

  Parameters:
    `kb` - the byte array to test.
  Returns:
    `true` if `kb`represents a possibly weak key. Returns `false` otherwise.

### clone

    public java.lang.Object clone()

  Description copied from interface: `IBlockCipher`

  Returns a clone of this instance.

  Specified by:
    `clone` in interface `IBlockCipher`
  Specified by:
    `clone` in class `BaseCipher`
  Returns:
    a clone copy of this instance.

### blockSizes

    public java.util.Iterator blockSizes()

  Description copied from interface: `IBlockCipher`

  Returns an `Iterator` over the supported block sizes. Each element returned by this object is an `Integer`.

  Returns:
    an `Iterator` over the supported block sizes.

### keySizes

    public java.util.Iterator keySizes()

  Description copied from interface: `IBlockCipher`

  Returns an `Iterator` over the supported key sizes. Each element returned by this object is an `Integer`.

  Returns:
    an `Iterator` over the supported key sizes.

### makeKey

    public java.lang.Object makeKey(byte[] kb,
                                    int bs)
                             throws java.security.InvalidKeyException

  Description copied from interface: `gnu.crypto.cipher.IBlockCipherSpi`

  Expands a user-supplied key material into a session key for a designated block size.

  Parameters:
    `kb` - the user-supplied key material.
    `bs` - the desired block size in bytes.
  Returns:
    an Object encapsulating the session key.
  Throws:
    `java.security.InvalidKeyException` - if the key data is invalid.

### encrypt

    public void encrypt(byte[] in,
                        int i,
                        byte[] out,
                        int o,
                        java.lang.Object K,
                        int bs)

  Description copied from interface: `gnu.crypto.cipher.IBlockCipherSpi`

  Encrypts exactly one block of plaintext.

  Parameters:
    `in` - the plaintext.
    `i` - index of `in` from which to start considering data.
    `out` - the ciphertext.
    `o` - index of `out` from which to store the result.
    `K` - the session key to use.
    `bs` - the block size to use.

### decrypt

    public void decrypt(byte[] in,
                        int i,
                        byte[] out,
                        int o,
                        java.lang.Object K,
                        int bs)

  Description copied from interface: `gnu.crypto.cipher.IBlockCipherSpi`

  Decrypts exactly one block of ciphertext.

  Parameters:
    `in` - the ciphertext.
    `i` - index of `in` from which to start considering data.
    `out` - the plaintext.
    `o` - index of `out` from which to store the result.
    `K` - the session key to use.
    `bs` - the block size to use.

For the latest news and information visit The GNU Crypto project

Copyright © 2001, 2002, 2003, 2004 Free Software Foundation, Inc.