Class DESKeySpec

java.lang.Object
javax.crypto.spec.DESKeySpec
All Implemented Interfaces:
KeySpec

public class DESKeySpec
extends Object
implements KeySpec
The key specification for a DES key.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int DES_KEY_LEN
    The length of a DES key in bytes.
  • Constructor Summary

    Constructors
    Constructor Description
    DESKeySpec​(byte[] key)
    Creates a new DESKeySpec from the first 8 bytes of the specified key data.
    DESKeySpec​(byte[] key, int offset)
    Creates a new DESKeySpec from the first 8 bytes of the specified key data starting at offset.
  • Method Summary

    Modifier and Type Method Description
    byte[] getKey()
    Returns a copy of the key.
    static boolean isParityAdjusted​(byte[] key, int offset)
    Returns whether the specified key data starting at offset is parity-adjusted.
    static boolean isWeak​(byte[] key, int offset)
    Returns whether the specified key data starting at offset is weak or semi-weak.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DES_KEY_LEN

      public static final int DES_KEY_LEN
      The length of a DES key in bytes.
      See Also:
      Constant Field Values
  • Constructor Details

    • DESKeySpec

      public DESKeySpec​(byte[] key) throws InvalidKeyException
      Creates a new DESKeySpec from the first 8 bytes of the specified key data.
      Parameters:
      key - the key data.
      Throws:
      InvalidKeyException - if the length of the specified key data is less than 8.
    • DESKeySpec

      public DESKeySpec​(byte[] key, int offset) throws InvalidKeyException
      Creates a new DESKeySpec from the first 8 bytes of the specified key data starting at offset.
      Parameters:
      key - the key data
      offset - the offset to start at.
      Throws:
      InvalidKeyException - if the length of the specified key data starting at offset is less than 8.
  • Method Details

    • getKey

      public byte[] getKey()
      Returns a copy of the key.
      Returns:
      a copy of the key.
    • isParityAdjusted

      public static boolean isParityAdjusted​(byte[] key, int offset) throws InvalidKeyException
      Returns whether the specified key data starting at offset is parity-adjusted.
      Parameters:
      key - the key data.
      offset - the offset to start checking at.
      Returns:
      true if the specified key data is parity-adjusted, false otherwise.
      Throws:
      InvalidKeyException - if the length of the key data starting at offset is less than 8, or the key is null.
    • isWeak

      public static boolean isWeak​(byte[] key, int offset) throws InvalidKeyException
      Returns whether the specified key data starting at offset is weak or semi-weak.
      Parameters:
      key - the key data.
      offset - the offset to start checking at.
      Returns:
      true if the specified key data is weak or semi-weak.
      Throws:
      InvalidKeyException - if the length of the key data starting at offset is less than 8, or it is null.