org.pf.security.crypto
Class HashMechanism

java.lang.Object
  extended by org.pf.security.crypto.HashMechanism
All Implemented Interfaces:
Serializable

public class HashMechanism
extends Object
implements Serializable

Contains all information about a hashing algorithm.

Version:
1.0
Author:
Manfred Duchrow
See Also:
Serialized Form

Field Summary
static HashMechanism MD5
           
static HashMechanism SALTED_MD5
           
static HashMechanism SALTED_SHA_1
           
static HashMechanism SALTED_SHA_2_256
           
static HashMechanism SALTED_SHA_2_384
           
static HashMechanism SALTED_SHA_2_512
           
static HashMechanism SHA_1
           
static HashMechanism SHA_2_256
           
static HashMechanism SHA_2_384
           
static HashMechanism SHA_2_512
           
 
Constructor Summary
HashMechanism(String hashMechanismName, CheckedHashAlgorithm algorithm, boolean isSalted)
          Creates a new instance that represents a particular hashing mechanism.
 
Method Summary
static HashMechanism create(CheckedHashAlgorithm algorithm)
          Creates a new instance that represents a particular unsalted hashing mechanism.
static HashMechanism create(CheckedHashAlgorithm algorithm, boolean isSalted)
          Creates a new instance that represents a particular hashing mechanism.
static HashMechanism create(String hashMechanismName, CheckedHashAlgorithm algorithm, boolean isSalted)
          Creates a new instance that represents a particular hashing mechanism.
static String createHashMechanismName(CheckedHashAlgorithm algorithm, boolean isSalted)
          Returns a name for the hashing mechanism that is defined by the given parameters.
static String createPrefix(String hashMechanismName)
          Returns a prefix for the provided hashing mechanism name.
 boolean equals(Object obj)
           
static HashMechanism findHashMechanism(String hashType)
          Tries to find a known (i.e. registered constant) hash mechanism for the given type name.
static HashMechanism findSaltedHashMechanism(String hashType)
           
static HashMechanism findUnsaltedHashMechanism(String hashType)
           
 CheckedHashAlgorithm getAlgorithm()
           
 String getAlgorithmName()
           
 int getBitLength()
           
 int getByteLength()
           
 String getName()
          Returns the name of this mechanism.
 String getPrefix()
           
 int hashCode()
           
 boolean isSalted()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MD5

public static final HashMechanism MD5

SHA_1

public static final HashMechanism SHA_1

SHA_2_256

public static final HashMechanism SHA_2_256

SHA_2_384

public static final HashMechanism SHA_2_384

SHA_2_512

public static final HashMechanism SHA_2_512

SALTED_MD5

public static final HashMechanism SALTED_MD5

SALTED_SHA_1

public static final HashMechanism SALTED_SHA_1

SALTED_SHA_2_256

public static final HashMechanism SALTED_SHA_2_256

SALTED_SHA_2_384

public static final HashMechanism SALTED_SHA_2_384

SALTED_SHA_2_512

public static final HashMechanism SALTED_SHA_2_512
Constructor Detail

HashMechanism

public HashMechanism(String hashMechanismName,
                     CheckedHashAlgorithm algorithm,
                     boolean isSalted)
Creates a new instance that represents a particular hashing mechanism.

Parameters:
hashMechanismName - The name of the mechanism to be used in the prefix.
algorithm - The underlying hashing algorithm.
isSalted - Defines whether or not the mechanism is salted.
Method Detail

createPrefix

public static String createPrefix(String hashMechanismName)
Returns a prefix for the provided hashing mechanism name.

Parameters:
hashMechanismName - The name to be used in the prefix (must not be null).

createHashMechanismName

public static String createHashMechanismName(CheckedHashAlgorithm algorithm,
                                             boolean isSalted)
Returns a name for the hashing mechanism that is defined by the given parameters.

Example: algorithm is "SHA-256" and isSalted = true. That returns "SSHA256".

Parameters:
algorithm - Defines the underlying hashing algorithm.
isSalted - Defines whether or not the mechanism is salted.

create

public static HashMechanism create(CheckedHashAlgorithm algorithm)
Creates a new instance that represents a particular unsalted hashing mechanism.

Parameters:
algorithm - The underlying hashing algorithm.

create

public static HashMechanism create(CheckedHashAlgorithm algorithm,
                                   boolean isSalted)
Creates a new instance that represents a particular hashing mechanism.

Parameters:
algorithm - The underlying hashing algorithm.
isSalted - Defines whether or not the mechanism is salted.

create

public static HashMechanism create(String hashMechanismName,
                                   CheckedHashAlgorithm algorithm,
                                   boolean isSalted)
Creates a new instance that represents a particular hashing mechanism.

Parameters:
hashMechanismName - The name of the mechanism to be used in the prefix.
algorithm - The underlying hashing algorithm.
isSalted - Defines whether or not the mechanism is salted.

findUnsaltedHashMechanism

public static HashMechanism findUnsaltedHashMechanism(String hashType)

findSaltedHashMechanism

public static HashMechanism findSaltedHashMechanism(String hashType)

findHashMechanism

public static HashMechanism findHashMechanism(String hashType)
Tries to find a known (i.e. registered constant) hash mechanism for the given type name.

Parameters:
hashType - The name of an hashing algorithm ("SHA-1") or the prefix (e.g. "{SSHA384}").
Returns:
The found mechanism or null if not found.

getName

public String getName()
Returns the name of this mechanism.


getAlgorithm

public CheckedHashAlgorithm getAlgorithm()

getByteLength

public int getByteLength()

getPrefix

public String getPrefix()

isSalted

public boolean isSalted()

getAlgorithmName

public String getAlgorithmName()

getBitLength

public int getBitLength()

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2013 Manfred Duchrow Consulting & Software. All Rights Reserved.