org.helidb.lang.hasher
Class StringToBigIntegerHasher

java.lang.Object
  extended by org.helidb.lang.hasher.AbstractMessageDigestStringHasher<BigInteger>
      extended by org.helidb.lang.hasher.StringToBigIntegerHasher
All Implemented Interfaces:
Hasher<String,BigInteger>

public class StringToBigIntegerHasher
extends AbstractMessageDigestStringHasher<BigInteger>

This Hasher uses a MessageDigest object with a configurable hash algorithm to produce a hash of a configurable length from a String. It does not support null values.

Any MessageDigest function may be used for creating the hash, as long as the hash it produces is at least as long as this object is configured to expect it to be. The hash bytes are extracted from the hash produced by the MessageDigest by taking its first bytes up to the configured length.

Since:
1.0
Author:
Karl Gustafsson
See Also:
StringToLongHasher
In_jar:
helidb-core

Field Summary
 
Fields inherited from class org.helidb.lang.hasher.AbstractMessageDigestStringHasher
DEFAULT_ALGORITHM
 
Constructor Summary
StringToBigIntegerHasher(int numLength)
           
StringToBigIntegerHasher(int numLength, int noOfBitsInMostSignificantByte)
           
StringToBigIntegerHasher(int numLength, int noOfBitsInMostSignificantByte, String hashAlgorithm, String provider, Charset cs)
           
 
Method Summary
 BigInteger fromBytes(byte[] barr)
          Interpret the serialized hash value.
 byte[] toBytes(BigInteger l)
          Serialize the hash to a byte array.
 
Methods inherited from class org.helidb.lang.hasher.AbstractMessageDigestStringHasher
assertNoMaskedBitsSet, createDigest, getHashLength, hash, isPreservingValues
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringToBigIntegerHasher

public StringToBigIntegerHasher(int numLength)
                         throws IllegalArgumentException
Throws:
IllegalArgumentException

StringToBigIntegerHasher

public StringToBigIntegerHasher(int numLength,
                                int noOfBitsInMostSignificantByte)
                         throws IllegalArgumentException
Throws:
IllegalArgumentException

StringToBigIntegerHasher

public StringToBigIntegerHasher(int numLength,
                                int noOfBitsInMostSignificantByte,
                                String hashAlgorithm,
                                String provider,
                                Charset cs)
                         throws IllegalArgumentException
Throws:
IllegalArgumentException
Method Detail

toBytes

public byte[] toBytes(BigInteger l)
Description copied from interface: Hasher
Serialize the hash to a byte array.

For a given Hasher object, the byte arrays returned by this method must always be of the same size.

Parameters:
l - The hash to serialize.
Returns:
The serialized hash.

fromBytes

public BigInteger fromBytes(byte[] barr)
Description copied from interface: Hasher
Interpret the serialized hash value.

Parameters:
barr - The serialized hash value.
Returns:
The hash value.