public class UnixCrypt extends Object
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.
Modifier and Type | Field and Description |
---|---|
private static int[] |
CON_SALT |
private static int[] |
COV2CHAR |
private static char[] |
SALT_CHARS |
private static boolean[] |
SHIFT2 |
private static int[][] |
SKB |
private static int[][] |
SPTRANS |
Constructor and Description |
---|
UnixCrypt() |
Modifier and Type | Method and Description |
---|---|
private static int[] |
body(int[] schedule,
int eSwap0,
int eSwap1) |
private static int |
byteToUnsigned(byte b) |
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.
|
private static int |
dEncrypt(int el,
int r,
int s,
int e0,
int e1,
int[] sArr) |
private static int[] |
desSetKey(byte[] key) |
private static int |
fourBytesToInt(byte[] b,
int offset) |
private static int |
hPermOp(int a,
int n,
int m) |
private static void |
intToFourBytes(int iValue,
byte[] b,
int offset) |
private static void |
permOp(int a,
int b,
int n,
int m,
int[] results) |
private static final int[] CON_SALT
private static final int[] COV2CHAR
private static final char[] SALT_CHARS
private static final boolean[] SHIFT2
private static final int[][] SKB
private static final int[][] SPTRANS
public UnixCrypt()
public static String crypt(byte[] original)
As no salt is given, a random one will be used.
original
- plaintext passwordpublic static String crypt(byte[] original, String salt)
Using unspecified characters as salt results incompatible hash values.
original
- plaintext passwordsalt
- a two character string drawn from [a-zA-Z0-9./] or null for a random oneIllegalArgumentException
- if the salt does not match the allowed patternpublic static String crypt(String original)
As no salt is given, a random one is used.
original
- plaintext passwordpublic static String crypt(String original, String salt)
original
- plaintext passwordsalt
- a two character string drawn from [a-zA-Z0-9./] or null for a random oneIllegalArgumentException
- if the salt does not match the allowed patternprivate static int[] body(int[] schedule, int eSwap0, int eSwap1)
private static int byteToUnsigned(byte b)
private static int dEncrypt(int el, int r, int s, int e0, int e1, int[] sArr)
private static int[] desSetKey(byte[] key)
private static int fourBytesToInt(byte[] b, int offset)
private static int hPermOp(int a, int n, int m)
private static void intToFourBytes(int iValue, byte[] b, int offset)
private static void permOp(int a, int b, int n, int m, int[] results)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses