public static int hash(String key,int bitSize,String input,String hashType){
  int bitLimitedHash;
  try {
    MessageDigest md=MessageDigest.getInstance(hashType);
    byte[] array=md.digest(input.getBytes());
    int hashInt=fromByteArray(array);
    bitLimitedHash=hashInt;
    if (bitSize < 32) {
      bitLimitedHash=(0xFFFFFFFF >>> (32 - bitSize)) & hashInt;
    }
    logger.debug("hashInt = " + hashInt + " bitLimitedHash = "+ bitLimitedHash);
  }
 catch (  NoSuchAlgorithmException e) {
    logger.info(e.toString());
    bitLimitedHash=hash(key,bitSize,input);
  }
  return bitLimitedHash;
}

public static int hash ( String key , int bitSize , String input , String hashType ) { int bitLimitedHash ; try { MessageDigest md = MessageDigest . getInstance ( hashType ) ; byte [ ] array = md . digest ( input . getBytes ( ) ) ; int hashInt = fromByteArray ( array ) ; bitLimitedHash = hashInt ; if ( bitSize < 32 ) { bitLimitedHash = ( 0xFFFFFFFF > > > ( 32 - bitSize ) ) & hashInt ; } logger . debug ( "hashInt = " + hashInt + " bitLimitedHash = " + bitLimitedHash ) ; } catch ( NoSuchAlgorithmException e ) { logger . info ( e . toString ( ) ) ; bitLimitedHash = hash ( key , bitSize , input ) ; } return bitLimitedHash ; }
hash method to optionally specify a hash type other than the default java hashcode ( ) hashtype must be md5 , sha - 1 , or sha - 256
