UnixCrypt (Apache Commons Codec 1.10 API)

org.apache.commons.codec.digest

## Class UnixCrypt

- java.lang.Object
- - org.apache.commons.codec.digest.UnixCrypt

-     public class UnixCrypt
      extends Object

  Unix crypt(3) algorithm implementation.

  This class only implements the traditional 56 bit DES based algorithm. Please use DigestUtils.crypt() for a method that distinguishes between all the algorithms supported in the current glibc's crypt().

  The Java implementation was taken from the JetSpeed Portal project (see org.apache.jetspeed.services.security.ldap.UnixCrypt).

  This class is slightly incompatible if the given salt contains characters that are not part of the allowed range [a-zA-Z0-9./].

  This class is immutable and thread-safe.

  Since:
    1.7
  Version:
    $Id: UnixCrypt.java 1429868 2013-01-07 16:08:05Z ggregory $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `UnixCrypt()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `crypt(byte[] original)` Generates a crypt(3) compatible hash using the DES algorithm.
    `static String` | `crypt(byte[] original, String salt)` Generates a crypt(3) compatible hash using the DES algorithm.
    `static String` | `crypt(String original)` Generates a crypt(3) compatible hash using the DES algorithm.
    `static String` | `crypt(String original, String salt)` Generates a crypt(3) compatible hash using the DES algorithm.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### UnixCrypt

          public UnixCrypt()

  - ### Method Detail

    - #### crypt

          public static String crypt(byte[] original)

      Generates a crypt(3) compatible hash using the DES algorithm.

      As no salt is given, a random one will be used.

      Parameters:
        `original` - plaintext password
      Returns:
        a 13 character string starting with the salt string

    - #### crypt

          public static String crypt(byte[] original,
                     String salt)

      Generates a crypt(3) compatible hash using the DES algorithm.

      Using unspecified characters as salt results incompatible hash values.

      Parameters:
        `original` - plaintext password
        `salt` - a two character string drawn from [a-zA-Z0-9./] or null for a random one
      Returns:
        a 13 character string starting with the salt string
      Throws:
        `IllegalArgumentException` - if the salt does not match the allowed pattern

    - #### crypt

          public static String crypt(String original)

      Generates a crypt(3) compatible hash using the DES algorithm.

      As no salt is given, a random one is used.

      Parameters:
        `original` - plaintext password
      Returns:
        a 13 character string starting with the salt string

    - #### crypt

          public static String crypt(String original,
                     String salt)

      Generates a crypt(3) compatible hash using the DES algorithm.
      Parameters:
        `original` - plaintext password
        `salt` - a two character string drawn from [a-zA-Z0-9./] or null for a random one
      Returns:
        a 13 character string starting with the salt string
      Throws:
        `IllegalArgumentException` - if the salt does not match the allowed pattern

Copyright © 2002–2014 The Apache Software Foundation. All rights reserved.