Package org.apache.commons.codec.digest
Class UnixCrypt
- java.lang.Object
-
- org.apache.commons.codec.digest.UnixCrypt
-
public class UnixCrypt extends java.lang.ObjectUnix crypt(3) algorithm implementation.This class only implements the traditional 56 bit DES based algorithm. Please use Crypt.crypt() for a method that distinguishes between all the algorithms supported in the current glibc's crypt().
The initial 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
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]CON_SALTprivate static int[]COV2CHARprivate static java.util.regex.PatternCRYPT_SALT_PATTERNprivate static java.lang.StringCRYPT_SALT_REGEXprivate static boolean[]SHIFT2private static int[][]SKBprivate static int[][]SPTRANS
-
Constructor Summary
Constructors Constructor Description UnixCrypt()Deprecated.TODO Make private in 2.0.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static int[]body(int[] schedule, int eSwap0, int eSwap1)private static intbyteToUnsigned(byte b)static java.lang.Stringcrypt(byte[] original)Generates a crypt(3) compatible hash using the DES algorithm.static java.lang.Stringcrypt(byte[] original, java.lang.String salt)Generates a crypt(3) compatible hash using the DES algorithm.static java.lang.Stringcrypt(java.lang.String original)Generates a crypt(3) compatible hash using the DES algorithm.static java.lang.Stringcrypt(java.lang.String original, java.lang.String salt)Generates a crypt(3) compatible hash using the DES algorithm.private static intdEncrypt(int el, int r, int s, int e0, int e1, int[] sArr)private static int[]desSetKey(byte[] key)private static intfourBytesToInt(byte[] b, int offset)private static inthPermOp(int a, int n, int m)private static voidintToFourBytes(int iValue, byte[] b, int offset)private static voidpermOp(int a, int b, int n, int m, int[] results)
-
-
-
Field Detail
-
CRYPT_SALT_REGEX
private static final java.lang.String CRYPT_SALT_REGEX
- See Also:
- Constant Field Values
-
CRYPT_SALT_PATTERN
private static final java.util.regex.Pattern CRYPT_SALT_PATTERN
-
CON_SALT
private static final int[] CON_SALT
-
COV2CHAR
private static final int[] COV2CHAR
-
SHIFT2
private static final boolean[] SHIFT2
-
SKB
private static final int[][] SKB
-
SPTRANS
private static final int[][] SPTRANS
-
-
Method Detail
-
body
private static int[] body(int[] schedule, int eSwap0, int eSwap1)
-
byteToUnsigned
private static int byteToUnsigned(byte b)
-
crypt
public static java.lang.String crypt(byte[] original)
Generates a crypt(3) compatible hash using the DES algorithm.A salt is generated for you using
SecureRandom.- Parameters:
original- Plaintext password.- Returns:
- A 13 character string starting with the salt string.
-
crypt
public static java.lang.String crypt(byte[] original, java.lang.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./]. The salt may be null, in which case a salt is generated for you usingB64.getRandomSalt(int). Only the first two characters are used, others are ignored.- Returns:
- A 13 character string starting with the salt string.
- Throws:
java.lang.IllegalArgumentException- Thrown if the salt does not match the allowed pattern.
-
crypt
public static java.lang.String crypt(java.lang.String original)
Generates a crypt(3) compatible hash using the DES algorithm.A salt is generated for you using
SecureRandom.- Parameters:
original- Plaintext password.- Returns:
- A 13 character string starting with the salt string.
-
crypt
public static java.lang.String crypt(java.lang.String original, java.lang.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./]. The salt may be null, in which case a salt is generated for you usingSecureRandom.- Returns:
- A 13 character string starting with the salt string.
- Throws:
java.lang.IllegalArgumentException- if the salt does not match the allowed pattern.
-
dEncrypt
private static int dEncrypt(int el, int r, int s, int e0, int e1, int[] sArr)
-
desSetKey
private static int[] desSetKey(byte[] key)
-
fourBytesToInt
private static int fourBytesToInt(byte[] b, int offset)
-
hPermOp
private static int hPermOp(int a, int n, int m)
-
intToFourBytes
private static void intToFourBytes(int iValue, byte[] b, int offset)
-
permOp
private static void permOp(int a, int b, int n, int m, int[] results)
-
-