Returns hash for resource.

@param resource $stream
@param string $algorithm

@return string
506436
private function getHash($stream, $algorithm = 'sha256')
    {
        $hash = hash_init($algorithm);
        hash_update_stream($hash, $stream);

        return hash_final($hash);
    }
531343
private function parseValue(Stream $stream)
    {
        if ($stream->current()->is(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED)) {
            return new ValueNode($stream->expects(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED)->getValue());
        }

        if ($stream->current()->is(Token::TYPE_NUMBER)) {
            $number = $stream->expects(Token::TYPE_NUMBER)->getValue();

            return new ValueNode(strpos($number, '.') === false ? intval($number) : floatval($number));
        }

        if ($stream->current()->is(Token::TYPE_CONSTANT)) {
            $constant = $stream->expects(Token::TYPE_CONSTANT)->getValue();

            switch ($constant) {
                case 'true':
                    return new ValueNode(true);

                case 'false':
                    return new ValueNode(false);

                case 'null':
                    return new ValueNode(null);

                default:
                    throw new ParserException(sprintf('Unexpected constant "%s" found', $constant));
            }
        }

        if ($stream->current()->equals(Token::TYPE_SYMBOL, '[')) {
            $stream->expects(Token::TYPE_SYMBOL, '[');

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, ']')) {
                $array = $this->parseList($stream);
            } else {
                $array = [];
            }

            $stream->expects(Token::TYPE_SYMBOL, ']');

            return new ValueNode($array);
        }

        if ($stream->current()->equals(Token::TYPE_SYMBOL, '{')) {
            $stream->expects(Token::TYPE_SYMBOL, '{');

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, '}')) {
                $hash = $this->parseHashList($stream);
            } else {
                $hash = [];
            }

            $stream->expects(Token::TYPE_SYMBOL, '}');

            return new ValueNode($hash);
        }

        if ($stream->current()->equals(Token::TYPE_KEYWORD, 'new')) {
            return $this->parseClass($stream);
        }

        throw new ParserException(sprintf('Can\'t parse the stream "%s".', $stream->humanize()));
    }
214134
public function get(string $algorithm): Algorithm
    {
        if (!$this->has($algorithm)) {
            throw new \InvalidArgumentException(\sprintf('The algorithm "%s" is not supported.', $algorithm));
        }

        return $this->algorithms[$algorithm];
    }
1183242
public static String getHashText(String plainText, String algorithm) throws NoSuchAlgorithmException {
	MessageDigest mdAlgorithm = MessageDigest.getInstance(algorithm);

	mdAlgorithm.update(plainText.getBytes());

	byte[] digest = mdAlgorithm.digest();
	StringBuffer hexString = new StringBuffer();

	for (int i = 0; i < digest.length; i++) {
	    plainText = Integer.toHexString(0xFF & digest[i]);

	    if (plainText.length() < 2) {
		plainText = "0" + plainText;
	    }

	    hexString.append(plainText);
	}

	return hexString.toString();
    }
397432
public function index($columns, $name = null, $algorithm = null)
    {
        $indexName = $name ?? md5(uniqid());

        return $this->indexCommand('index', $columns, $indexName, $algorithm);
    }
47481
function hashJson(data, algorithm) {
    return Q.Promise(function (resolve, reject) {
        try {
            resolve(hashJsonSync(data, algorithm));
        }
        catch (error) {
            reject(error);
        }
    });
}
925844
public function readByte(Stream $stream)
    {
        $char = $stream->read(1);
        $byte = ord($char);

        return $byte;
    }
601758
private function generateHashForUrl($key, $route, $method)
    {
        $path = preg_replace('~\s+~', '-', $key);
        $httpMethod = $this->getRouteParam($route, 'methods.0');
        $classMethod = implode('-', $this->splitCamelCaseToWords($method));
        
        $hash = $path .'::'. $httpMethod .'::'. $classMethod;
        
        return strtolower($hash);
    }
1321764
private function getOpenSslAlgorithm(string $algorithm) : int
    {
        switch ($algorithm) {
            case Algorithms::RSA_SHA256:
                return OPENSSL_ALGO_SHA256;
            case Algorithms::RSA_SHA384:
                return OPENSSL_ALGO_SHA384;
            case Algorithms::RSA_SHA512:
                return OPENSSL_ALGO_SHA512;
            default:
                throw new InvalidArgumentException("Algorithm \"$algorithm\" is not an OpenSSL algorithm");
        }
    }
1253820
public static String hash(String algorithm, String str, String charsetName) {
		try {
			byte[] digest = MessageDigest
				.getInstance(algorithm)
				.digest(strToBytesWithCharset(str, charsetName));
			return EncodingUtils.hex(digest);
		} catch (NoSuchAlgorithmException e) {
			throw new IllegalArgumentException("Unsupported algorithm: " + algorithm, e);
		}
	}
309140
private function decorateWithHashes(Stream $stream, array &$data)
    {
        // Make sure that a tree hash is calculated.
        $stream = new HashingStream($stream, new TreeHash(),
            function ($result) use (&$data) {
                $data['checksum'] = bin2hex($result);
            }
        );

        // Make sure that a linear SHA256 hash is calculated.
        $stream = new HashingStream($stream, new PhpHash('sha256'),
            function ($result) use (&$data) {
                $data['ContentSHA256'] = bin2hex($result);
            }
        );

        return $stream;
    }
442309
private function canKeyBeUsedWithAlgorithm($algorithm, JWKInterface $key)
    {
        if (null === $algorithm) {
            return 0;
        }
        if ($key->has('alg')) {
            return $algorithm === $key->get('alg') ? 1 : false;
        }

        return 0;
    }
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();
    }
507138
private function decorateWithHashes(Stream $stream, array &$data)
    {
        // Decorate source with a hashing stream
        $hash = new PhpHash('sha256');
        return new HashingStream($stream, $hash, function ($result) use (&$data) {
            $data['ContentSHA256'] = bin2hex($result);
        });
    }
935609
public function hash($value, $algorithm = 'md5')
    {
        try {
            return hash($algorithm, $value);
        } catch (\Exception $e) {
            error_log('Please check that the '.$algorithm.' does exists because it failed when trying to run. We are expecting a valid algorithm such as md5 or sha512 etc. ['.$e->getMessage().']');

            return $value;
        }
    }
385719
public function passwordNeedsRehash(string $passwordHash, string $algorithm): bool
    {
        return $this->passwordHashService->passwordNeedsRehash($passwordHash, $algorithm);
    }
997245
public static function Ds(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1)
    {
        $rdata = new DS();
        $rdata->setKeyTag($keyTag);
        $rdata->setAlgorithm($algorithm);
        $rdata->setDigest($digest);
        $rdata->setDigestType($digestType);

        return $rdata;
    }