org.esupportail.cas.server.util.crypt
Class Crypt

java.lang.Object
  extended by org.esupportail.cas.server.util.crypt.Crypt

public abstract class Crypt
extends java.lang.Object

This class offers encryption methods used by handlers encrypting users' passwords and comparing them to a reference (file or database).

Author:
Jean-Baptiste Daniel

Field Summary
private static java.lang.String[] supportedEncryptions
          An array containing the encryptions supported by the module.
 
Constructor Summary
Crypt()
           
 
Method Summary
private static java.lang.String cryptDES(java.lang.String password, java.lang.String salt)
          DES Encryption of a string using a salt.
private static java.lang.String cryptMD5(java.lang.String password, java.lang.String salt)
          MD5 Encryption of a string using a salt.
private static java.lang.String getDESSalt(java.lang.String encryptedString)
          Retrieve the salt of a DES encrypted string.
private static java.lang.String getMD5Salt(java.lang.String encryptedString)
          Retrieve the salt of an MD5 encrypted string.
static boolean isEncryptionSupported(java.lang.String encryption)
          Tell if an encryption is supported.
static boolean match(java.lang.String encryption, java.lang.String password, java.lang.String encryptedPassword)
          Compare a password with its encryption using an encryption method.
private static boolean matchDES(java.lang.String password, java.lang.String encryptedPassword)
          DES comparison.
private static boolean matchMD5(java.lang.String password, java.lang.String encryptedPassword)
          MD5 comparison.
private static boolean matchPAMMD5(java.lang.String password, java.lang.String encryptedPassword)
          Linux PAM MD5 comparison.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

supportedEncryptions

private static java.lang.String[] supportedEncryptions
An array containing the encryptions supported by the module.

Constructor Detail

Crypt

public Crypt()
Method Detail

cryptDES

private static java.lang.String cryptDES(java.lang.String password,
                                         java.lang.String salt)
DES Encryption of a string using a salt.

Parameters:
password - the password to encrypt
salt - the salt to encrypt with
Returns:
the encrypted string (null if the salt is null).

cryptMD5

private static java.lang.String cryptMD5(java.lang.String password,
                                         java.lang.String salt)
MD5 Encryption of a string using a salt.

Parameters:
password - the password to encrypt
salt - the salt to encrypt with
Returns:
the encrypted string (null if the salt is null).

getDESSalt

private static java.lang.String getDESSalt(java.lang.String encryptedString)
Retrieve the salt of a DES encrypted string.

Parameters:
encryptedString - a DES encrypted string
Returns:
the salt of the encrypted string, or null on error.

getMD5Salt

private static java.lang.String getMD5Salt(java.lang.String encryptedString)
Retrieve the salt of an MD5 encrypted string.

Parameters:
encryptedString - an MD5 encrypted string
Returns:
the salt of the encrypted string, or null on error.

isEncryptionSupported

public static boolean isEncryptionSupported(java.lang.String encryption)
Tell if an encryption is supported.

Parameters:
encryption - an encryption
Returns:
true if the encryption is supported, false otherwise.

match

public static boolean match(java.lang.String encryption,
                            java.lang.String password,
                            java.lang.String encryptedPassword)
                     throws java.lang.Exception
Compare a password with its encryption using an encryption method.

Parameters:
encryption - an encryption method (must be supported)
password - the password
encryptedPassword - the encrypted password
Returns:
true if password matches, false otherwise
Throws:
java.lang.Exception - when encryption is not supprted.

matchDES

private static boolean matchDES(java.lang.String password,
                                java.lang.String encryptedPassword)
DES comparison.

Parameters:
password - a clear password.
encryptedPassword - an already encrypted password.
Returns:
true if password matches, false otherwise.

matchMD5

private static boolean matchMD5(java.lang.String password,
                                java.lang.String encryptedPassword)
MD5 comparison. This method compares a clear password with a MD5 hash as created by 'md5sum' or MySQL's 'MD5()'.

Parameters:
password - a clear password.
encryptedPassword - an already encrypted password.
Returns:
true if password matches, false otherwise.

matchPAMMD5

private static boolean matchPAMMD5(java.lang.String password,
                                   java.lang.String encryptedPassword)
Linux PAM MD5 comparison. This method compares a clear password with a Linux PAM / OpenBSD / FreeBSD compatible md5-encoded password hash.

Parameters:
password - a clear password.
encryptedPassword - an already encrypted password.
Returns:
true if password matches, false otherwise.