Hash a file's contents

@param string $file
@param string $algo

@return mixed  String on success, false if $algo is not available
4701
private function hashFile($file, $algo)
    {
        if (!file_exists($file)) {
            return false;
        }

        $msg = file_get_contents($file);

        return $this->hash($msg, $algo);
    }
939299
protected function read($file)
    {
        $data = null;
        $key  = $file;
        $file = $this->getFileName($file);

        if ( file_exists($file))
        {
            // if cache file not expire
            if (filemtime($file) >= time())
            {
                echo "read cache<br/>";
                $data = file_get_contents($file);
                $data = ($this->base64Encode) ? base64_decode($data) : $data;
                $data = unserialize($data);
                static::$keys[$key] = true;
            }
            else
            {
                unset(static::$keys[$key]);
                unlink($file);
            }
        }

        return $data;
    }
54533
public function elixir($file, $tag = false)
    {
        if ($tag) {
            return craft()->elixir->withTag($file);    
        }
        return craft()->elixir->version($file);
    }
488932
function hash(str, algo, encoding) {
  return crypto
    .createHash(algo || 'sha1')
    .update(str)
    .digest(encoding || 'hex');
}
125807
public static function hash($str, $algo = self::MD5_HASH, $hmacKey = '', $rawOuput = false, $salt = null, $passwordAlgo = PASSWORD_DEFAULT, $passwordOptions = [])
    {
        if ($hmacKey && in_array($algo, [self::MD5_HASH, self::SHA1_HASH])) {
            return hash_hmac($algo, $str, $hmacKey, $rawOuput);
        }

        switch ($algo) {
        case self::MD5_HASH:
            $hashCode = md5($str, $rawOuput);
            break;
        case self::SHA1_HASH:
            $hashCode = sha1($str, $rawOuput);
            break;
        case self::CRYPT_HASH:
            $hashCode = crypt($str, $salt);
            break;
        case self::PASSWORD_HASH:
            $hashCode = password_hash($str, $passwordAlgo, $passwordOptions);
            break;
        default:
            $hashCode = md5($str, $rawOuput);
        }

        return $hashCode;
    }
454172
public static function hash($object, $algoOrCtx = 'md5', $raw = FALSE)
	{
		if (is_string($algoOrCtx)) {
			$ctx = hash_init($algoOrCtx);
		} else {
			$ctx = $algoOrCtx;
		}

		if (isset($object->name)) {
			hash_update($ctx, 'name');
			hash_update($ctx, (string)$object->name);
		}

		if (isset($object->insertionPoint)) {
			hash_update($ctx, 'insertionPoint');
			hash_update($ctx, (string)$object->insertionPoint);
		}

		if (isset($object->content)) {
			hash_update($ctx, 'content');
			hash_update($ctx, (string)$object->content);
		}

		if (is_string($algoOrCtx)) {
			return hash_final($ctx, $raw);
		} else {
			return null;
		}
	}
916933
public function hash($algo = 'sha1')
    {
        $algos = new ArrayObject(hash_algos());
        if (!$algos->inArray($algo)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_HASH_ALGO, [$algo]);
        }

        $this->val(hash($algo, $this->val()));

        return $this;
    }
1350530
function load_file($file)
    {
        if (!file_exists($file) || !is_readable($file)) return false;
        $data = file($file);
        foreach ($data as $line) {
            $line = trim($line);
            if (($line == '') || ($line == '#')) continue;
            $line = preg_split('/\s+/', $line, 2);
            if (count($line) < 2) continue;
            $exts = $line[1];
            // if there's a comment on this line, remove it
            $hash_pos = strpos($exts, '#');
            if ($hash_pos !== false) $exts = substr($exts, 0, $hash_pos);
            $this->set($line[0], $exts);
        }
        return true;
    }
701269
private function hashFile(File $file)
    {
        $arr = [];

        foreach ($this->layouts as $layout) {
            if (strpos($layout, '_templates') === false) {
                $layout = '_templates'.DIRECTORY_SEPARATOR.$layout;
            }

            $layoutPathName = $this->sourceDirectory.DIRECTORY_SEPARATOR.$layout.'.phtml';
            if (file_exists($layoutPathName)) {
                array_push($arr, sha1_file($layoutPathName));
            }
        }

        array_push($arr, $file->getLastModified());

        return sha1(implode('.', $arr));
    }
991591
public function hash($string, $algo)
    {
        if (true === empty($string)) {
            $string = microtime() . uniqid();
        }

        return hash($algo, $string);
    }
654837
public function encryptString($algo, $string, $key = null)
    {     
        if (!empty($algo) && !empty($string)) {   
            if ($key == null) {
                $ctx = hash_init($algo);
            } else {
                $ctx = hash_init($algo, HASH_HMAC, $key);
                hash_update($ctx, $string);
            }
            return hash_final($ctx);
        }
        return false;
    }
375857
public static function passwordHash(string $password, string $algo = PASSWORD_BCRYPT): string
    {
        return password_hash($password, $algo);
    }
672835
public static function eTagChanged($file, $etag = null) {

        $etag = trim($etag, '" ');

        if (!$etag) {
            return true;
        }

        if (!file_exists($file)) {
            throw new Exception("File '$file' not exists");
        }

        if (!is_file($file)) {
            throw new Exception("'$file' is not file");
        }

        if (!is_readable($file)) {
            throw new Exception("File '$file' not readable");
        }

        return hash_file('crc32', $file) !== $etag;
    }
754511
private function FileGetContents($file) {
    $fileObj = new SplFileObject($file, 'r');
    while (!$fileObj->flock(LOCK_EX)) {
      usleep(1);
    }
    $str = $fileObj->fread($fileObj->getSize());
    $fileObj->flock(LOCK_UN);
    return $str;
  }
800296
public static function get($file = false) {

        if ($file && self::isFile($file)) {

            return file_get_contents($file);
        }

        return false;
    }
235102
public static function HmacStringStretching ($count, $data, $key, $algo = self::DEFAULT_HASH_ALGORITHM) {
		for ($i = 0;$i < $count;$i++) {
			$data = static::HmacString($data, $key, $algo);
		}
		return $data;
	}
1022183
public static function fileToArray($file)
    {
        if (! is_file($file) && ! filter_var($file, FILTER_VALIDATE_URL)) {
            self::arrayToFile([], $file);
        }

        $json = @file_get_contents($file);
        $array = json_decode($json, true);
        $lastError = JsonLastError::check();

        return $array === null || !is_null($lastError) ? false : $array;
    }