Generate a keyed hash value using the HMAC
method and the contents of a given file.
(PHP 5 >= 5.1.2, PECL hash >= 1.1)

@param string
@param string
@param string
@param bool
@return string
428617
public function hmacFile($algorithm, $filename, $key, $raw_output = false)
    {
        return hash_hmac_file($algorithm, $filename, $key, $raw_output);
    }
1156589
public static function createHash($string) {
		$salt = substr(str_replace('+', '.', base64_encode(pack('N4', mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 22);
		return crypt($string, '$2a$10$' . $salt . '$'); // we use Blowfish with a cost of 10
	}
201350
function setHash($hash)
    {
        $this->hashParam = $hash = strtolower($hash);
        switch ($hash) {
            case 'md5-96':
            case 'sha1-96':
            case 'sha256-96':
            case 'sha512-96':
                $hash = substr($hash, 0, -3);
                $this->l = 12; // 96 / 8 = 12
                break;
            case 'md2':
            case 'md5':
                $this->l = 16;
                break;
            case 'sha1':
                $this->l = 20;
                break;
            case 'sha256':
                $this->l = 32;
                break;
            case 'sha384':
                $this->l = 48;
                break;
            case 'sha512':
                $this->l = 64;
        }

        switch ($hash) {
            case 'md2':
                $mode = CRYPT_HASH_MODE == self::MODE_HASH && in_array('md2', hash_algos()) ?
                    self::MODE_HASH : self::MODE_INTERNAL;
                break;
            case 'sha384':
            case 'sha512':
                $mode = CRYPT_HASH_MODE == self::MODE_MHASH ? self::MODE_INTERNAL : CRYPT_HASH_MODE;
                break;
            default:
                $mode = CRYPT_HASH_MODE;
        }

        switch ($mode) {
            case self::MODE_MHASH:
                switch ($hash) {
                    case 'md5':
                        $this->hash = MHASH_MD5;
                        break;
                    case 'sha256':
                        $this->hash = MHASH_SHA256;
                        break;
                    case 'sha1':
                    default:
                        $this->hash = MHASH_SHA1;
                }
                return;
            case self::MODE_HASH:
                switch ($hash) {
                    case 'md5':
                        $this->hash = 'md5';
                        return;
                    case 'md2':
                    case 'sha256':
                    case 'sha384':
                    case 'sha512':
                        $this->hash = $hash;
                        return;
                    case 'sha1':
                    default:
                        $this->hash = 'sha1';
                }
                return;
        }

        switch ($hash) {
            case 'md2':
                $this->b = 16;
                $this->hash = array($this, '_md2');
                break;
            case 'md5':
                $this->b = 64;
                $this->hash = array($this, '_md5');
                break;
            case 'sha256':
                $this->b = 64;
                $this->hash = array($this, '_sha256');
                break;
            case 'sha384':
            case 'sha512':
                $this->b = 128;
                $this->hash = array($this, '_sha512');
                break;
            case 'sha1':
            default:
                $this->b = 64;
                $this->hash = array($this, '_sha1');
        }

        $this->ipad = str_repeat(chr(0x36), $this->b);
        $this->opad = str_repeat(chr(0x5C), $this->b);
    }
235705
public function encode($string)
    {

        if (empty($string) || empty($this->key)) {
            throw new \Exception("Can not encrypt with an empty key or no data");
            return false;
        }

        $publicKey = $this->generateKey($string);
        $privateKey = $this->key;


        //Get a SHA-1 hashKey 
        $hashKey = sha1($privateKey . "+" . (string)$publicKey);

        $stringArray = str_split($string);
        $hashArray = str_split($hashKey);
        $cipherNoise = str_split($publicKey, 2);

        $counter = 0;

        for ($i = 0; $i < sizeof($stringArray); $i++) {
            if ($counter > 40)
                $counter = 0;
            $cryptChar = ord((string)$stringArray[$i]) + ord((string)$hashArray[$counter]);
            $cryptChar -= floor($cryptChar / 127) * 127;
            $cipherStream[$i] = dechex($cryptChar);
            $counter++;
        }
        //print_R($cipherNoise);

        $cipherNoiseSize = count($cipherNoise);

        $cipher = implode("|x", $cipherStream);
        $cipher .= "|x::|x" . ord((string)$cipherNoiseSize) . "|x";
        $cipher .= implode("|x", $cipherNoise);


        //echo $cipher;

        return $cipher;
    }
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, '')
}
1004711
static String getMd5Hash(byte[] bytes) throws NoSuchAlgorithmException {

        String hash;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bytes);
            byte[] digest = md.digest();

            char[] hexCode = "0123456789ABCDEF".toCharArray();
            StringBuilder r = new StringBuilder(digest.length * 2);
            for (byte b : digest) {
                r.append(hexCode[(b >> 4) & 0xF]);
                r.append(hexCode[(b & 0xF)]);
            }

            hash = r.toString().toUpperCase();
        }catch (NoSuchAlgorithmException e){
            throw e;
        }
        return hash;
    }
670752
public function getKeyStr($hash = true)
    {
        $key =  $this->key . self::$INDEX_SEPERATOR . $this->groupId . self::$TAG_SEPERATOR . implode(self::$TAG_SEPERATOR, $this->gatherTags());
        if($hash) {
             $key = md5($key);
        }
        return $key;
    }
915610
private function createHmac(
        string $iv,
        string $keySalt,
        string $cipher,
        string $value,
        string $authenticationKey
    ) : string {
        return \hash_hmac(self::$hmacAlgorithm, self::$version . $cipher . $iv . $keySalt . $value, $authenticationKey);
    }
936645
public static function decode($value, $key = false)
	{
		$key ? static::$crypter->setKey($key) : static::$crypter->setKey(static::safe_b64decode(static::$config['crypto_key']));
		static::$crypter->setIV(static::safe_b64decode(static::$config['crypto_iv']));

		$value = static::safe_b64decode($value);
		if ($value = static::validate_hmac($value))
		{
			return static::$crypter->decrypt($value);
		}
		else
		{
			return false;
		}
	}
149476
public function getHash(
        bool $raw = false,
        int $outputSize = \SODIUM_CRYPTO_GENERICHASH_BYTES,
        string $personalization = ''
    ): string {
        if ($raw) {
            return Util::raw_hash(
                $personalization . $this->data,
                $outputSize
            );
        }
        return Util::hash(
            $personalization . $this->data,
            $outputSize
        );
    }
1195417
public static function ValidRandomHash ($random_hash, $string, $salt, $hmac_key, $secret_key_length = self::SECRET_KEY_LENGTH, $algo = self::DEFAULT_HASH_ALGORITHM) {
		$secret_hash_length = strlen($random_hash) - $secret_key_length;

		$string_seed = hexdec(hash('crc32b', $string));
		$string_seed = str_pad($string_seed, $secret_key_length, $string_seed);

		$salt_seed = hexdec(hash('crc32b', $salt));
		$salt_seed = str_pad($salt_seed, $secret_key_length, $salt_seed);

		$index_list = [];
		for ($i = 0;$i < $secret_key_length;$i++) {
			$index = $string_seed[$i] * $salt_seed[$i] * $i + $string_seed[$i] + 1;
			$index = $index > $secret_hash_length  ? $secret_hash_length % $index : $index;
			if ($index < 1) {
				$index++;
			} else if ($index >= $secret_hash_length) {
				$index--;
			}
			$index_list[] = $index;
		}
		$kr_index_list = $index_list;

		krsort($kr_index_list);

		$secret_key = [];
		$secret_hash = $random_hash;
		foreach ($kr_index_list as $index) {
			$secret_key[] = substr($secret_hash, $index, 1);
			$secret_hash = substr($secret_hash, 0, $index) . substr($secret_hash, $index + 1);
		}
		krsort($secret_key);
		$secret_key = implode('', $secret_key);

		$secret_hash = Hash::HmacString("\\". $string .'_'. $salt .'/'. $hmac_key, $secret_key, $algo);
		for ($i = 0;$i < $secret_key_length;$i++) {
			$secret_hash = substr($secret_hash, 0, $index_list[$i]) . $secret_key[$i] . substr($secret_hash, $index_list[$i]);
		}

		return $random_hash === $secret_hash;
	}
1175696
function setHash($a1hash)
    {
        $a1hash = (string) $a1hash;
        if (strlen($a1hash) !== 32)
            // MD5 hash error
            throw new \InvalidArgumentException(sprintf('The A1 Hash (%s) seems is invalid.', $a1hash));
        
        $this->hash = $a1hash;
        return $this;
    }
959674
public function getHash(string $algorithm = 'sha256', bool $raw = false): string
	{
		return hash_file($algorithm, $this->getPathname(), $raw);
	}
686686
private static String getHash(String str, String algorithm) throws NoSuchAlgorithmException {

        MessageDigest md = MessageDigest.getInstance(algorithm);
        md.update(str.getBytes());

        byte byteData[] = md.digest();

        StringBuilder hexString = new StringBuilder();
        for (int i = 0; i < byteData.length; i++) {
            String hex = Integer.toHexString(0xff & byteData[i]);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }

        return hexString.toString();
    }
825503
function getHash(str, algorithm) {
  algorithm = algorithm || 'md5';
  var hash = crypto.createHash(algorithm);
  hash.end(str);
  return hash.read();
}
220121
protected function createHashString($hashData = array())
    {
        if (count($hashData) == 0) {
            $this->errorMessage[] = 'HASH_DATA: hashData is empty, so we can not generate hash string ';
            return false;
        }

        $hashString = '';
        $cunter = 1;
        foreach ($hashData as $field) {
            if (is_array($field)) {
                $this->errorMessage[] = 'HASH_ARRAY: No multi-dimension array allowed!';
                return false;
            }
            $hashString .= strlen(StripSlashes($field)).$field;
            if ($this->commMethod != 'alu') {
                $this->debugMessage[] = 'HASH_VALUE_' . $cunter .'('.strlen($field).'): '. $field;
            }
            $cunter++;
        }

        $this->hashString = $hashString;
        if ($this->commMethod != 'alu') {
            $this->debugMessage[] = 'HASH string: ' . $this->hashString;
        }
        $this->hashCode = $this->hmac($this->secretKey, $this->hashString);
        return $this->hashCode;
    }
828456
static function genpwd($apikey, $textpwd, $salt = null, $algorythm = 'sha512') {

		$pwd = [];

		// generate password salt and hash
		if ($salt === null) {
			$pwd['salt'] = hash($algorythm, (uniqid(rand(), true)), false);
		}
		else { # salt provided
			$pwd['salt'] = $salt;
		}

		$lockedpwd = hash_hmac($algorythm, $textpwd, $apikey, false);
		$pwd['verifier'] = hash_hmac($algorythm, $lockedpwd, $pwd['salt'], false);
		$pwd['algorythm'] = $algorythm;

		return $pwd;
	}