|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcs138.common.HashGenerator
public class HashGenerator
Used to generate hash values (represented as BigIntegers) from Strings. Parameters for hashing include the maximum byte length of the hash value, the radix of the hash value's representation, and the name of algorithm used to generate the hash value. The algorithms available are the same algorithms available to the java.security.MessageDigest. The values generated by the hash method will always be positive and reside between 0 and the maximum unsigned number representable in the byte length of the hash. The space used by the BigInteger which is actually used represent the value of the hash is always larger than the hash byte length.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_ALGO
The default MessageDigest algorithm used. |
Method Summary | |
---|---|
java.math.BigInteger |
add(java.math.BigInteger a,
java.math.BigInteger b)
Adds the specified integers and reduces the result modulus the value returned by getModulus(). |
static java.math.BigInteger |
divideEvenly(java.math.BigInteger target,
java.math.BigInteger divisor)
Attempts divide the specified target by the specified divisor. |
int |
getBitLength()
Returns the number of bits required to store the unsigned representation of the largest hash value generated by this HashFactory. |
int |
getByteLength()
Returns the number of bytes required to store the unsigned representation of the largest hash value generated by this HashFactory. |
static HashGenerator |
getHashFactory(int byteLength,
int radix)
Creates and returns a HashFactory object using the default MessageDigest algorithm and the specified byte length and radix. |
static HashGenerator |
getHashFactory(int byteLength,
int radix,
java.lang.String algorithm)
Creates and returns a HashFactory object using the specified MessageDigest algorithm, byte length, and radix. |
int |
getMaximumDigits()
Returns the number of digits used to represent the largest hash value generated by this HashFactory. |
java.math.BigInteger |
getMaximumValue()
Returns the largest hash value generated by this HashFactory. |
java.math.BigInteger |
getModulus()
Returns the modulus value for the space of values generated by this HashFactory. |
int |
getRadix()
Returns the radix of the hash values generated by this HashFactory. |
java.math.BigInteger |
hash(java.lang.String string)
Generates the hash value of the specified string. |
java.util.List<java.math.BigInteger> |
saltedHashes(java.lang.String string,
int number)
Generates a list of hash values from the specified string by appending the numbers 0 through number - 1 to the string and calling hash() on each produced string. |
java.lang.String |
toString(java.math.BigInteger value)
Returns the String representation of the hash value in the radix of this HashFactory. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_ALGO
Method Detail |
---|
public static HashGenerator getHashFactory(int byteLength, int radix)
byteLength
- The maximum byte length of the generated hashes.radix
- The radix of the generated hashes.
java.lang.IllegalArgumentException
- When the specified radix and byte length are incompatible.public static HashGenerator getHashFactory(int byteLength, int radix, java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
byteLength
- The maximum byte length of the generated hashes.radix
- The radix of the generated hashes.algorithm
- The name of the MessageDigest algorithm to use.
java.security.NoSuchAlgorithmException
- When a MessageDigest algorithm with the specified name does
not exist.
java.lang.IllegalArgumentException
- When the specified radix and byte length are incompatible.public java.math.BigInteger hash(java.lang.String string)
string
- The string to hash.
public java.util.List<java.math.BigInteger> saltedHashes(java.lang.String string, int number)
string
- The string to generate hashes with.number
- The number of hashes to generate.
public static java.math.BigInteger divideEvenly(java.math.BigInteger target, java.math.BigInteger divisor) throws java.lang.IllegalArgumentException
target
- The number to be divided.divisor
- The number to divide the target with.
java.lang.IllegalArgumentException
- If divisor does not divide target evenly.public java.math.BigInteger add(java.math.BigInteger a, java.math.BigInteger b)
a
- One integer.b
- The other integer.
public int getMaximumDigits()
public int getRadix()
public int getByteLength()
public java.math.BigInteger getMaximumValue()
public java.math.BigInteger getModulus()
public java.lang.String toString(java.math.BigInteger value)
value
- A hash value.
public int getBitLength()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |