Creates a base 64 encoded SHA-1 hash of the specified string.

@param str The string to hash.
@return The hashed and encoded string.
190555
public static String hash(final String str)
        {
        try
            {
            final MessageDigest md = new Sha1();
            final byte[] hashed = md.digest(str.getBytes("UTF-8"));
            final byte[] encoded = Base64.encodeBase64(hashed);
            return new String(encoded, "UTF-8");
            }
        catch (final UnsupportedEncodingException e)
            {
            LOG.error("Encoding error??", e);
            return "";
            }
        }
307191
public static char[] encodeHex(String str, Charset charset) {
		return encodeHex(StrUtil.bytes(str, charset), true);
	}
1244669
public static String encodeStringInBase64(String str, Charset charset) {
        return new String(Base64.encodeBase64(str.getBytes(charset)));
    }
837134
public static int apHash(String str) {
		int hash = 0;

		for (int i = 0; i < str.length(); i++) {
			hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str.charAt(i) ^ (hash >> 3)) : (~((hash << 11) ^ str.charAt(i) ^ (hash >> 5)));
		}

		// return (hash & 0x7FFFFFFF);
		return hash;
	}
1001915
private static function hash($str)
    {
        $hash = 0;
        $str = str_split($str, 1);
        foreach ($str as $char) {
            $hash = ($hash << 4) + ord($char);
            $g = $hash & (0xf << (self::INT_SIZE - 4));
            if ($g !== 0) {
                $hash = $hash ^ ($g >> self::INT_SIZE - 8);
                $hash = $hash ^ $g;
            }
        }
        return $hash;
    }
1138125
function hash (str) {
  return crypto
    .createHash('sha1')
    .update(str, 'ascii')
    .digest('base64')
    .replace(PLUS_GLOBAL_REGEXP, '-')
    .replace(SLASH_GLOBAL_REGEXP, '_')
    .replace(EQUAL_GLOBAL_REGEXP, '')
}
155870
public static int elfHash(String str) {
		int hash = 0;
		int x = 0;

		for (int i = 0; i < str.length(); i++) {
			hash = (hash << 4) + str.charAt(i);
			if ((x = (int) (hash & 0xF0000000L)) != 0) {
				hash ^= (x >> 24);
				hash &= ~x;
			}
		}

		return hash & 0x7FFFFFFF;
	}
303032
protected function hash($str) {
        $seed  = 131;
        $seed2 = 137;
        $hash  = 0;
        // Make hash more sensitive for short string like 'a', 'b', 'c'
        $str .= 'x';
        $max = intval(9007199254740991 / $seed2);
        for ($i = 0, $ilen = mb_strlen($str, 'UTF-8'); $i < $ilen; $i++) {
            if ($hash > $max) {
                $hash = intval($hash / $seed2);
            }
            $hash = $hash * $seed + $this->getCharCode(mb_substr($str, $i, 1, 'UTF-8'));
        }
        return $hash;
    }
729991
public static long mixHash(String str) {
		long hash = str.hashCode();
		hash <<= 32;
		hash |= fnvHash(str);
		return hash;
	}
166624
public static function BKDRHash( $str ) {

        $hval = 0;
        $len  = strlen($str);

        /*
         * 4-bytes integer we will directly take
         * its int value as the final hash value.
        */
        $seed = 131;    // 31 131 1313 13131 131313 etc..
        if ( $len <= 11 && is_numeric($str) ) {
            $hval = intval($str);
        } else {
            for ( $i = 0; $i < $len; $i++ ) {
                $hval = (int) ($hval * $seed + (ord($str[$i]) % 127));
            }
        }

        return ($hval & 0x7FFFFFFF);
    }
589411
public static byte[] hexToBytes(String str) {
        if (str == null)
            return null;
        byte[] hexChars;
        try {
            hexChars = str.toUpperCase().getBytes("ISO_8859-1");
        } catch (UnsupportedEncodingException e) {
            throw new NexmoUnexpectedException("ISO_8859_1 is an unsupported encoding in this JVM");
        }
        int size = hexChars.length;
        byte[] bytes = new byte[size / 2];
        int first;
        int second;

        int rIndex = 0;
        // Convert to bytes.
        for (int i = 0; i+1 <size; i= i + 2) {

            // Convert first
            first = hexChars[i];
            if (first < 58)
                first = ((first - 48) * 16); // 0 - 9
            else
                first = ((first - 55) * 16); // A - F

            // Convert second
            second = hexChars[i + 1];
            if (second < 58)
                second = second - 48; // 0 - 9
            else
                second = second - 55; // A - F

            //Value must be between -128 and 127
            int total = (first + second);
            if (total > 127)
                total = (256 + total);

            bytes[rIndex] = (byte) total;
            rIndex++;
        }
        return bytes;
    }
515420
public static BigInteger encodeStringToInteger(String str) {
        byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
        byte[] res;
        if ((bytes[0] & 0b1000_0000) >> 7 == 1) {
            res = new byte[bytes.length + 1];
            res[0] = 0;
            System.arraycopy(bytes, 0, res, 1, bytes.length);
        } else {
            res = bytes;
        }
        BigInteger r = new BigInteger(res);
        assert r.compareTo(BigInteger.ZERO) > 0;
        return r;
    }
311185
public static String getSHA256String(String str) {
        MessageDigest messageDigest = getMessageDigest(SHA256);
        return getHashString(str, messageDigest);
    }
290397
function sha2(str) {
  var md = forge.md.sha256.create();
  md.update(str);
  return md.digest().toHex()
}
1033376
public static byte[] stringToHash(String s) {
        if (s.length() % 2 != 0) {
            throw new IllegalArgumentException("Invalid hash string: " + s);
        }
        byte[] hash = new byte[s.length() / 2];
        for (int i = 0; i < s.length(); i += 2) {
            byte b = (byte) ((hexDigitValue(s.charAt(i)) << 4) + hexDigitValue(s.charAt(i + 1)));
            hash[i / 2] = b;
        }
        return hash;
    }
617103
public static String sha256(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest messageDigest;
        messageDigest = MessageDigest.getInstance("SHA-256");
        byte[] hash = messageDigest.digest(string.getBytes("UTF-8"));
        return String.valueOf(Hex.encodeHex(hash));
    }
727828
public static String sha1( String string ) {
        try {
            byte[] sha1 = SecureHash.getHash(SecureHash.Algorithm.SHA_1, string.getBytes());
            return SecureHash.asHexString(sha1);
        } catch (NoSuchAlgorithmException e) {
            throw new SystemFailureException(e);
        }
    }