kerberos.packets
Class DES

java.lang.Object
  extended bykerberos.packets.DES

public class DES
extends java.lang.Object

This is the class for Data Encryption Standard (DES) keys. See FIPS PUB 46-1 or DEA defined in ANSI X3.92-1981 for a complete specification.

DES is the most widely used block cipher, although it is nowadays normally used repeatedly for each piece of plain-text and is called triple-DES. This is because the 56-bit key-size of the normal DES is too small to offer complete security.

The CDS for a DES key is DES(key) with key a string of 16 hexadecimal digits to create a specific key or DES(?) for a random DES object.

This implementation is done from the description given in Schneier's Applied Cryptography.

Author:
Logi Ragnarsson (logi@logi.org)
See Also:
org.logi.crypto.keys.TriDES

Constructor Summary
DES()
          Create a new random DES key.
DES(byte[] key)
          Create a new DES key with the key bits from key[0..7].
DES(long key)
          Create a new DES key with the key bits from key.
 
Method Summary
 int cipherBlockSize()
          The block-size for the DES cipher is 8 bytes.
 void decrypt(byte[] source, int i, byte[] dest, int j)
          Decrypt one block of data.
 void encrypt(byte[] source, int i, byte[] dest, int j)
          Encrypt one block of data.
 boolean equals(java.lang.Object o)
          Return true iff the two keys are equivalent.
 java.lang.String getAlgorithm()
          The name of the algorithm is "DES".
 byte[] getKey()
          Return the key-bits for this key as an array of 8 bytes.
 int getSize()
          The key-size for the DES cipher is 56 bits.
static java.lang.String hexString(long a)
           
static long makeLong(byte[] buf, int i, int length)
          Convert a byte array to a long.
static int pickBits(int a, byte[] bits)
          Construct an int by picking bits from another int.
static long pickBits(long a, byte[] bits)
          Construct an long by picking bits from another long.
 int plainBlockSize()
          The block-size for the DES cipher is 8 bytes.
 java.lang.String toString()
          Return a CDS for this key.
static void writeBytes(long a, byte[] dest, int i, int length)
          Write a long to a byte array.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DES

public DES()
Create a new random DES key.


DES

public DES(byte[] key)
Create a new DES key with the key bits from key[0..7].


DES

public DES(long key)
Create a new DES key with the key bits from key.

Method Detail

plainBlockSize

public int plainBlockSize()
The block-size for the DES cipher is 8 bytes.


cipherBlockSize

public int cipherBlockSize()
The block-size for the DES cipher is 8 bytes.


getSize

public int getSize()
The key-size for the DES cipher is 56 bits.


getAlgorithm

public java.lang.String getAlgorithm()
The name of the algorithm is "DES".


equals

public boolean equals(java.lang.Object o)
Return true iff the two keys are equivalent.


getKey

public byte[] getKey()
Return the key-bits for this key as an array of 8 bytes.


toString

public java.lang.String toString()
Return a CDS for this key.

See Also:
org.logi.crypto.Crypto#fromString

encrypt

public void encrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Encrypt one block of data. The plaintext is taken from source[i..i+7] and ciphertext is written to dest[j..j+7]


decrypt

public void decrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Decrypt one block of data. The encrypted data is taken from dest[i..i+7] and plaintext is written to source[j..j+7].


makeLong

public static final long makeLong(byte[] buf,
                                  int i,
                                  int length)
Convert a byte array to a long. Bits are collected from buf[i..i+length-1].


hexString

public static final java.lang.String hexString(long a)

pickBits

public static final int pickBits(int a,
                                 byte[] bits)
Construct an int by picking bits from another int. The number in bits[i] is the index of the bit within a that should be put at index i in the result.

The most-significant bit is number 0.


pickBits

public static final long pickBits(long a,
                                  byte[] bits)
Construct an long by picking bits from another long. The number in bits[i] is the index of the bit within a that should be put at index i in the result.

The most-significant bit is number 0.


writeBytes

public static final void writeBytes(long a,
                                    byte[] dest,
                                    int i,
                                    int length)
Write a long to a byte array. Bits from a are written to dest[i..i+length-1].