org.PingOO.DLAI.lib.util
Class PasswordCodec

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.util.PasswordCodec

public final class PasswordCodec
extends java.lang.Object

Offers an implementation of the UNIX crypt command in Java.
Based upon C source code written by Eric Young

Since:
PingOO 2.0
Version:
2.0
Author:
Eric Young (eay@psych.uq.oz.au), John F. Dumas (jdumas@zgs.com), Fabrice Bouyé (bouye@cur-archamps.fr)

Field Summary
private static int[] con_salt
           
private static int[] cov_2char
           
private static int ITERATIONS
          The total number of iterations.
private static boolean[] shifts2
           
private static int[][] skb
           
private static int[][] SPtrans
           
 
Constructor Summary
private PasswordCodec()
          Hides the constructor from the outside.
 
Method Summary
private static int[] body(int[] schedule, int Eswap0, int Eswap1)
           
private static int byteToUnsigned(byte b)
           
private static int D_ENCRYPT(int L, int R, int S, int E0, int E1, int[] s)
           
private static int[] des_set_key(byte[] key)
           
static java.lang.String encode(java.lang.String original, java.lang.String salt)
          Ecrypts a string using the UNIX crypt algorithm.
private static int fourBytesToInt(byte[] b, int offset)
           
private static int HPERM_OP(int a, int n, int m)
           
private static void intToFourBytes(int iValue, byte[] b, int offset)
           
static void main(java.lang.String[] args)
          Allows to run the crypt algorithm by itself.
private static void PERM_OP(int a, int b, int n, int m, int[] results)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

ITERATIONS

private static final int ITERATIONS
The total number of iterations.

con_salt

private static final int[] con_salt

shifts2

private static final boolean[] shifts2

skb

private static final int[][] skb

SPtrans

private static final int[][] SPtrans

cov_2char

private static final int[] cov_2char
Constructor Detail

PasswordCodec

private PasswordCodec()
Hides the constructor from the outside.
Method Detail

byteToUnsigned

private static final int byteToUnsigned(byte b)
Parameters:
b -  

fourBytesToInt

private static int fourBytesToInt(byte[] b,
                                  int offset)
Parameters:
b -  
offset -  

intToFourBytes

private static final void intToFourBytes(int iValue,
                                         byte[] b,
                                         int offset)
Parameters:
iValue -  
b -  
offset -  

PERM_OP

private static final void PERM_OP(int a,
                                  int b,
                                  int n,
                                  int m,
                                  int[] results)
Parameters:
a -  
b -  
n -  
m -  
results -  

HPERM_OP

private static final int HPERM_OP(int a,
                                  int n,
                                  int m)
Parameters:
a -  
n -  
m -  

des_set_key

private static int[] des_set_key(byte[] key)
Parameters:
key -  

D_ENCRYPT

private static final int D_ENCRYPT(int L,
                                   int R,
                                   int S,
                                   int E0,
                                   int E1,
                                   int[] s)
Parameters:
L -  
R -  
S -  
EO -  
E1 -  
s -  

body

private static final int[] body(int[] schedule,
                                int Eswap0,
                                int Eswap1)
Parameters:
schedule -  
Eswap0 -  
Eswap1 -  

encode

public static final java.lang.String encode(java.lang.String original,
                                            java.lang.String salt)
                                     throws java.lang.NullPointerException
Ecrypts a string using the UNIX crypt algorithm.
Here is a copy of the crypt man page from LINUX Debian.
Note : in this implementation the parameter key has been replaced by the parameter original.

NAME
crypt - password and data encryption

SYNOPSIS
#define _XOPEN_SOURCE
#include <unistd.h>

char *crypt(const char *key, const char *salt);

DESCRIPTION
crypt is the password encryption function. It is based on the Data Encryption Standard algorithm with variations intended (among other things) to discourage use of hardware implementations of a key search.

key is a user's typed password.

salt is a two-character string chosen from the set [a-zA-Z0-9./]. This string is used to perturb the algorithm in one of 4096 different ways.

By taking the lowest 7 bit of each character of the key, a 56-bit key is obtained. This 56-bit key is used to encrypt repeatedly a constant string (usually a string consisting of all zeros). The returned value points to the encrypted password, a series of 13 printable ASCII characters (the first two characters represent the salt itself). The return value points to static data whose content is overwritten by each call.

Warning : The key space consists of 2**56 equal 7.2e16 possible values. Exhaustive searches of this key space are possible using massively parallel computers. Software, such as crack(1), is available which will search the portion of this key space that is generally used by humans for passwords. Hence, password selection should, at minimum, avoid common words and names. The use of a passwd(1) program that checks for crackable passwords during the selection process is recommended.

The DES algorithm itself has a few quirks which make the use of the crypt(3) interface a very poor choice for anything other than password authentication. If you are planning on using the crypt(3) interface for a cryptography project, don't do it : get a good book on encryption and one of the widely available DES libraries.

CONFORMING TO
SVID, X/OPEN, BSD 4.3

SEE ALSO
login(1), passwd(1), encrypt(3), getpass(3), passwd(5)

September 3, 1994
Parameters:
original - The string to crypt.
salt - The 2 character array needed to crypt key.
Returns:
The crypted string.
Throws:
java.lang.NullPointerException - If original is null.

main

public static void main(java.lang.String[] args)
Allows to run the crypt algorithm by itself.
Parameters:
args -