com.cafesoft.core.util
Class DigestString

java.lang.Object
  |
  +--com.cafesoft.core.util.DigestString

public class DigestString
extends Object

DigestString represents a String value that may or may not have been transformed by a "one way hash" algorithm, usually called a "message digest". If the String is "digested", it's standard form is:

 {algorithm}(digestvalue[salt])
 
where:

Since:
10/31/01

Constructor Summary
DigestString(String digestString)
          Create a new DigestString.
 
Method Summary
static String createDigestString(String s, String algorithm)
          Returns a digest of the strValue based on the specified alogrithm.
static String createDigestString(String strValue, String algorithm, byte[] salt)
          Return a digestString without an algorithm label.
static String createDigestString(String strValue, String algorithm, byte[] salt, String label)
          Return a digestString with an algorithm label.
 String getAlgorithm()
          Return the algorithm of this DigestString.
 String getDigest()
          Return the digest of this DigestString.
 int getDigestSize()
          Return the length of this DigestString.
 String getLabel()
          Return the algorithm label of this DigestString.
 byte[] getSalt()
          Return the salt of this DigestString.
 boolean isDigestString()
          If a label prefix indicating the digest algorithm does not exist, then we cannot determine the digest algorithm (or the digest string is clear text).
 boolean isEqual(String cleartext)
          Determine if a cleartext value is the same a as suspect DigestString.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DigestString

public DigestString(String digestString)
Create a new DigestString.

Parameters:
digestString - the "possibly" digestString from which the DigestString will be constructed.
Method Detail

isDigestString

public boolean isDigestString()
If a label prefix indicating the digest algorithm does not exist, then we cannot determine the digest algorithm (or the digest string is clear text).

Returns:
true if the digest string starts with the pattern {algorithm}, else return false.
See Also:
getDigest()

getDigest

public String getDigest()
Return the digest of this DigestString.


getDigestSize

public int getDigestSize()
Return the length of this DigestString.


getAlgorithm

public String getAlgorithm()
Return the algorithm of this DigestString.

Returns:
the code corresponding to the digest algorithm if the value is actually a digested String. If not digested, return null;
See Also:
isDigestString()

getLabel

public String getLabel()
Return the algorithm label of this DigestString.

Returns:
the code label corresponding to the digest algorithm if the value is actually a digested String. The label must be obtained from the original value for case sensitive comparision. If not digested, return null;
See Also:
isDigestString()

getSalt

public byte[] getSalt()
Return the salt of this DigestString.


createDigestString

public static String createDigestString(String strValue,
                                        String algorithm,
                                        byte[] salt)
                                 throws NoSuchAlgorithmException
Return a digestString without an algorithm label.

Parameters:
strValue - the String value to hash
algorithm - the digest algorithm to be applied
salt - the random "salt" bytes
Throws:
NoSuchAlgorithmException - if the digest algorithm is not registered with the Java Security Provider Interface.

createDigestString

public static String createDigestString(String strValue,
                                        String algorithm,
                                        byte[] salt,
                                        String label)
                                 throws NoSuchAlgorithmException
Return a digestString with an algorithm label.

Parameters:
strValue - the string value to hash
algorithm - the digest algorithm to be applied
salt - the random "salt" bytes
label - the digest string algorithm prefix (e.g., {CRYPT})
Throws:
NoSuchAlgorithmException - if the digest algorithm is not registered with the Java Security Provider Interface.

createDigestString

public static String createDigestString(String s,
                                        String algorithm)
Returns a digest of the strValue based on the specified alogrithm.

Parameters:
s - The String to be digested
algorithm - The algorithm to use: Clear Text, SSHA, SHA, SMD5 and MD5 are supported.

isEqual

public boolean isEqual(String cleartext)
Determine if a cleartext value is the same a as suspect DigestString. (Usage: a user enters a password and it needs to be compared to a queried value that may or may not be a DigestString). Note that even if the suspect DigestString is only cleartext, this method with still perform a valid comparison.

Parameters:
cleartext - The cleartext value to compare to the suspect DigestString.
Returns:
true if the cleartext value is the same as the suspect DigestString else return false.


Generated on 8:41:50 AM June 06, 2005, © 1996-2005 Cafésoft LLC. All rights reserved.