Class UnixCrypt
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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int[]body(int[] schedule, int eSwap0, int eSwap1) private static intbyteToUnsigned(byte b) static Stringcrypt(byte[] original) Generates a crypt(3) compatible hash using the DES algorithm.static StringGenerates a crypt(3) compatible hash using the DES algorithm.static StringGenerates a crypt(3) compatible hash using the DES algorithm.static StringGenerates 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 Details
-
CON_SALT
private static final int[] CON_SALT -
COV2CHAR
private static final int[] COV2CHAR -
SALT_CHARS
private static final char[] SALT_CHARS -
SHIFT2
private static final boolean[] SHIFT2 -
SKB
private static final int[][] SKB -
SPTRANS
private static final int[][] SPTRANS
-
-
Constructor Details
-
UnixCrypt
public UnixCrypt()
-
-
Method Details
-
crypt
Generates a crypt(3) compatible hash using the DES algorithm.A salt is generated for you using
ThreadLocalRandom; for more secure salts consider usingSecureRandomto generate your own salts and callingcrypt(byte[], String).- Parameters:
original- plaintext password- Returns:
- a 13 character string starting with the salt string
-
crypt
Generates a crypt(3) compatible hash using the DES algorithm.Using unspecified characters as salt results incompatible hash values.
- Parameters:
original- plaintext passwordsalt- a two character string drawn from [a-zA-Z0-9./]. The salt may be null, in which case a salt is generated for you usingThreadLocalRandom; for more secure salts consider usingSecureRandomto generate your own salts.- Returns:
- a 13 character string starting with the salt string
- Throws:
IllegalArgumentException- if the salt does not match the allowed pattern
-
crypt
Generates a crypt(3) compatible hash using the DES algorithm.A salt is generated for you using
ThreadLocalRandom; for more secure salts consider usingSecureRandomto generate your own salts and callingcrypt(String, String).- Parameters:
original- plaintext password- Returns:
- a 13 character string starting with the salt string
-
crypt
Generates a crypt(3) compatible hash using the DES algorithm.- Parameters:
original- plaintext passwordsalt- a two character string drawn from [a-zA-Z0-9./]. The salt may be null, in which case a salt is generated for you usingThreadLocalRandom; for more secure salts consider usingSecureRandomto generate your own salts.- Returns:
- a 13 character string starting with the salt string
- Throws:
IllegalArgumentException- if the salt does not match the allowed pattern
-
body
private static int[] body(int[] schedule, int eSwap0, int eSwap1) -
byteToUnsigned
private static int byteToUnsigned(byte b) -
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)
-