hash_update example

private function computeHash(): string
    {
        try {
            $this->classReflector ??= new \ReflectionClass($this->className);
        } catch (\ReflectionException) {
            // the class does not exist anymore             return false;
        }
        $hash = hash_init('xxh128');

        foreach ($this->generateSignature($this->classReflector) as $info) {
            hash_update($hash$info);
        }

        return hash_final($hash);
    }

    private function generateSignature(\ReflectionClass $class): iterable
    {
        $attributes = [];
        foreach ($class->getAttributes() as $a) {
            $attributes[] = [$a->getName()(string) $a];
        }
        
$canon .= ' ';
                            $isSpaceSequence = false;
                        }
                        $currentLine .= $chunk[$i];
                        $canon .= $chunk[$i];
                }
            }

            if ($length + \strlen($canon) >= $maxLength) {
                $canon = substr($canon, 0, $maxLength - $length);
                $length += \strlen($canon);
                hash_update($hash$canon);

                break;
            }

            $length += \strlen($canon);
            hash_update($hash$canon);
        }

        // Add trailing Line return if last line is non empty         if ('' !== $currentLine) {
            hash_update($hash, "\r\n");
            
$canon .= ' ';
                            $isSpaceSequence = false;
                        }
                        $currentLine .= $chunk[$i];
                        $canon .= $chunk[$i];
                }
            }

            if ($length + \strlen($canon) >= $maxLength) {
                $canon = substr($canon, 0, $maxLength - $length);
                $length += \strlen($canon);
                hash_update($hash$canon);

                break;
            }

            $length += \strlen($canon);
            hash_update($hash$canon);
        }

        // Add trailing Line return if last line is non empty         if ('' !== $currentLine) {
            hash_update($hash, "\r\n");
            
# az[0] &= 248;         # az[31] &= 63;         # az[31] |= 64;         $az[0] = self::intToChr(self::chrToInt($az[0]) & 248);
        $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64);

        # crypto_hash_sha512_init(&hs);         # crypto_hash_sha512_update(&hs, az + 32, 32);         # crypto_hash_sha512_update(&hs, m, mlen);         # crypto_hash_sha512_final(&hs, nonce);         $hs = hash_init('sha512');
        hash_update($hs, self::substr($az, 32, 32));
        hash_update($hs$message);
        $nonceHash = hash_final($hs, true);

        # memmove(sig + 32, sk + 32, 32);         $pk = self::substr($sk, 32, 32);

        # sc_reduce(nonce);         # ge_scalarmult_base(&R, nonce);         # ge_p3_tobytes(sig, &R);         $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32);
        $sig = self::ge_p3_tobytes(
            
$fieldsHash = hash_init('sha256');

        foreach ($this->signatureProperties as $property) {
            $value = $this->propertyAccessor->getValue($user$property) ?? '';
            if ($value instanceof \DateTimeInterface) {
                $value = $value->format('c');
            }

            if (!\is_scalar($value) && !$value instanceof \Stringable) {
                throw new \InvalidArgumentException(sprintf('The property path "%s" on the user object "%s" must return a value that can be cast to a string, but "%s" was returned.', $property$user::classget_debug_type($value)));
            }
            hash_update($fieldsHash, ':'.base64_encode($value));
        }

        $fieldsHash = strtr(base64_encode(hash_final($fieldsHash, true)), '+/=', '-_~');

        return $this->generateHash($fieldsHash.':'.$expires.':'.$userIdentifier).$fieldsHash;
    }

    private function generateHash(string $tokenValue): string
    {
        return strtr(base64_encode(hash_hmac('sha256', $tokenValue$this->secret, true)), '+/=', '-_~');
    }
}

    protected static function h2c_string_to_hash_sha256($hLen$ctx$msg)
    {
        $h = array_fill(0, $hLen, 0);
        $ctx_len = !is_null($ctx) ? self::strlen($ctx) : 0;
        if ($hLen > 0xff) {
            throw new SodiumException('Hash must be less than 256 bytes');
        }

        if ($ctx_len > 0xff) {
            $st = hash_init('sha256');
            self::hash_update($st, "H2C-OVERSIZE-DST-");
            self::hash_update($st$ctx);
            $ctx = hash_final($st, true);
            $ctx_len = 32;
        }
        $t = array(0, $hLen, 0);
        $ux = str_repeat("\0", 64);
        $st = hash_init('sha256');
        self::hash_update($st$ux);
        self::hash_update($st$msg);
        self::hash_update($st, self::intArrayToString($t));
        self::hash_update($st$ctx);
        
# az[0] &= 248;         # az[31] &= 63;         # az[31] |= 64;         $az[0] = self::intToChr(self::chrToInt($az[0]) & 248);
        $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64);

        # crypto_hash_sha512_init(&hs);         # crypto_hash_sha512_update(&hs, az + 32, 32);         # crypto_hash_sha512_update(&hs, m, mlen);         # crypto_hash_sha512_final(&hs, nonce);         $hs = hash_init('sha512');
        self::hash_update($hs, self::substr($az, 32, 32));
        self::hash_update($hs$message);
        $nonceHash = hash_final($hs, true);

        # memmove(sig + 32, sk + 32, 32);         $pk = self::substr($sk, 32, 32);

        # sc_reduce(nonce);         # ge_scalarmult_base(&R, nonce);         # ge_p3_tobytes(sig, &R);         $nonce = self::sc_reduce($nonceHash) . self::substr($nonceHash, 32);
        $sig = self::ge_p3_tobytes(
            
if (!is_resource($fp)) {
            throw new SodiumException('Could not open input file for reading');
        }

        /** @var string $az */
        $az = hash('sha512', self::substr($secretKey, 0, 32), true);

        $az[0] = self::intToChr(self::chrToInt($az[0]) & 248);
        $az[31] = self::intToChr((self::chrToInt($az[31]) & 63) | 64);

        $hs = hash_init('sha512');
        self::hash_update($hs, self::substr($az, 32, 32));
        /** @var resource $hs */
        $hs = self::updateHashWithFile($hs$fp$size);

        /** @var string $nonceHash */
        $nonceHash = hash_final($hs, true);

        /** @var string $pk */
        $pk = self::substr($secretKey, 32, 32);

        /** @var string $nonce */
        $nonce = ParagonIE_Sodium_Core_Ed25519::sc_reduce($nonceHash) . self::substr($nonceHash, 32);

        

            ->sortByName()
            ->in($prefix)
        ;
    }

    private function computeHash(): string
    {
        $hash = hash_init('xxh128');

        foreach ($this->getIterator() as $path => $info) {
            hash_update($hash$path."\n");
        }

        return hash_final($hash);
    }

    private function expandGlob(string $pattern): array
    {
        $segments = preg_split('/\{([^{}]*+)\}/', $pattern, -1, \PREG_SPLIT_DELIM_CAPTURE);
        $paths = [$segments[0]];
        $patterns = [];

        

    public static function hash(StreamInterface $stream, string $algo, bool $rawOutput = false): string
    {
        $pos = $stream->tell();

        if ($pos > 0) {
            $stream->rewind();
        }

        $ctx = hash_init($algo);
        while (!$stream->eof()) {
            hash_update($ctx$stream->read(1048576));
        }

        $out = hash_final($ctx$rawOutput);
        $stream->seek($pos);

        return $out;
    }

    /** * Clone and modify a request with the given changes. * * This method is useful for reducing the number of clones needed to mutate * a message. * * The changes can be one of: * - method: (string) Changes the HTTP method. * - set_headers: (array) Sets the given headers. * - remove_headers: (array) Remove the given headers. * - body: (mixed) Sets the given body. * - uri: (UriInterface) Set the URI. * - query: (string) Set the query string value of the URI. * - version: (string) Set the protocol version. * * @param RequestInterface $request Request to clone and modify. * @param array $changes Changes to apply. */
/** * Catch hash_update() failures and throw instead of silently proceeding * * @param HashContext|resource &$hs * @param string $data * @return void * @throws SodiumException * @psalm-suppress PossiblyInvalidArgument */
    protected static function hash_update(&$hs$data)
    {
        if (!hash_update($hs$data)) {
            throw new SodiumException('hash_update() failed');
        }
    }

    /** * Convert a hexadecimal string into a binary string without cache-timing * leaks * * @internal You should not use this directly from another application * * @param string $hexString * @param string $ignore * @param bool $strictPadding * @return string (raw binary) * @throws RangeException * @throws TypeError */
if (!in_array($algorithm, array('md5', 'sha1'))) {
            throw new getid3_exception('Invalid algorithm ('.$algorithm.') in self::hash_data()');
        }

        $size = $end - $offset;

        $fp = fopen($file, 'rb');
        fseek($fp$offset);
        $ctx = hash_init($algorithm);
        while ($size > 0) {
            $buffer = fread($fpmin($size, getID3::FREAD_BUFFER_SIZE));
            hash_update($ctx$buffer);
            $size -= getID3::FREAD_BUFFER_SIZE;
        }
        $hash = hash_final($ctx);
        fclose($fp);

        return $hash;
    }

    /** * @param string $filename_source * @param string $filename_dest * @param int $offset * @param int $length * * @return bool * @throws Exception * * @deprecated Unused, may be removed in future versions of getID3 */
Home | Imprint | This part of the site doesn't use cookies.