org.aspsimon.termcomp.infrastructure.utility
Class Hash

java.lang.Object
  extended by org.aspsimon.termcomp.infrastructure.utility.Hash

@Name(value="hash")
public class Hash
extends java.lang.Object

This class offers a basic hashing functionality. Uses MessageDigest from java.security to create the hash and Hex from org.apache.commons.codec.binary to hex-encode the resulting byte-array. Not quite sure where the idea for this class came from, but it certainly works. This class is basically a Seam component, and it should be accessed with the static method Hash.getInstance().

Version:
$Revision: 104 $
Author:
binabik

Constructor Summary
Hash()
           
 
Method Summary
 java.lang.String getCharset()
          Return the character set this object works with.
 java.lang.String getHashFunction()
          Determine which hash function is used to generate the digest.
static Hash getInstance()
          Get an instance of this class.
 java.lang.String hash(java.lang.String password)
          Create the required digest of a String.
 void setCharset(java.lang.String charset)
          Change the default character set this object works with.
 void setHashFunction(java.lang.String hashFunction)
          Set a different hash function for creating the digest.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hash

public Hash()
Method Detail

hash

public java.lang.String hash(java.lang.String password)
Create the required digest of a String.

Parameters:
password - The string which should be hashed.
Returns:
A Hex-encoded String of the hash value.

getCharset

public java.lang.String getCharset()
Return the character set this object works with. Default is UTF-8.

Returns:
The character encoding expected.

setCharset

public void setCharset(java.lang.String charset)
Change the default character set this object works with. The default character set is UTF-8.

Parameters:
charset - The character set to use.

getHashFunction

public java.lang.String getHashFunction()
Determine which hash function is used to generate the digest. The default hash function is MD5.

Returns:
The hash function used.

setHashFunction

public void setHashFunction(java.lang.String hashFunction)
Set a different hash function for creating the digest. This can be any function that java.security.MessageDigest supports.

Parameters:
hashFunction - The hash function to be used.
See Also:
MessageDigest

getInstance

public static Hash getInstance()
Get an instance of this class.

Returns:
A Hash object.