org.objectweb.jonas.security.realm.lib
Class HashHelper

java.lang.Object
  extended by org.objectweb.jonas.security.realm.lib.HashHelper

public class HashHelper
extends java.lang.Object

Methods to hash Strings. All the methods in here are static so HashHelper should never be instantiated.

Author:
Andy Armstrong, andy@tagish.com , Yann Petiot for the modifications, Florent Benoit modifications for integration in JOnAS

Field Summary
static java.lang.String DEFAULT_ALGO
          The default algorithm
 
Method Summary
static HashPassword getHashPassword(java.lang.String password)
          Return the haspassword object from a string.
static java.lang.String hashPassword(char[] pwd)
          Performs the default algorithm hashing on the supplied password and return a char array containing the password as a printable string.
static java.lang.String hashPassword(char[] pwd, java.lang.String algo)
          Performs an algorithm specified by the user hashing on the supplied password and return a char array containing the encrypted password as a printable string.
static java.lang.String hashPassword(java.lang.String string, java.lang.String algo)
          Performs an algorithm specified by the user hashing on the supplied password and return a char array containing the encrypted password as a printable string.
static char[] hexDump(byte[] src)
          Turn a byte array into a char array containing a printable hex representation of the bytes.
static void smudge(byte[] pwd)
          Zero the contents of the specified array.
static void smudge(char[] pwd)
          Zero the contents of the specified array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ALGO

public static final java.lang.String DEFAULT_ALGO
The default algorithm

See Also:
Constant Field Values
Method Detail

getHashPassword

public static HashPassword getHashPassword(java.lang.String password)
Return the haspassword object from a string. It extracts algorithm and password from the string

Parameters:
password - contain password and algorithm
Returns:
the haspassword object

hexDump

public static char[] hexDump(byte[] src)
Turn a byte array into a char array containing a printable hex representation of the bytes. Each byte in the source array contributes a pair of hex digits to the output array.

Parameters:
src - the source array
Returns:
a char array containing a printable version of the source data

smudge

public static void smudge(char[] pwd)
Zero the contents of the specified array. Typically used to erase temporary storage that has held plaintext passwords so that we don't leave them lying around in memory.

Parameters:
pwd - the array to zero

smudge

public static void smudge(byte[] pwd)
Zero the contents of the specified array.

Parameters:
pwd - the array to zero

hashPassword

public static java.lang.String hashPassword(char[] pwd)
                                     throws java.security.NoSuchAlgorithmException
Performs the default algorithm hashing on the supplied password and return a char array containing the password as a printable string. The hash is computed on the low 8 bits of each character.

Parameters:
pwd - The password to hash
Returns:
a string representation of the hash password
Throws:
java.security.NoSuchAlgorithmException - if this is not a valid algorithm

hashPassword

public static java.lang.String hashPassword(char[] pwd,
                                            java.lang.String algo)
                                     throws java.security.NoSuchAlgorithmException
Performs an algorithm specified by the user hashing on the supplied password and return a char array containing the encrypted password as a printable string. The hash is computed on the low 8 bits of each character.

Parameters:
pwd - The password to hash
algo - The type of Message Digest Algorithms
Returns:
a string representation of the hash password
Throws:
java.security.NoSuchAlgorithmException - if the algorithm can not be found

hashPassword

public static java.lang.String hashPassword(java.lang.String string,
                                            java.lang.String algo)
                                     throws java.security.NoSuchAlgorithmException
Performs an algorithm specified by the user hashing on the supplied password and return a char array containing the encrypted password as a printable string. The hash is computed on the low 8 bits of each character.

Parameters:
string - The password to hash
algo - The type of Message Digest Algorithms
Returns:
a string representation of the hash password
Throws:
java.security.NoSuchAlgorithmException - if the algorithm can not be found