WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Самая быстрая Тема-конструктор для WordPress
функция не описана

ParagonIE_Sodium_File::generichash() public WP 1.0

Calculate the BLAKE2b hash of a file.

{} Это метод класса: ParagonIE_Sodium_File{}

Хуков нет.

Возвращает

Строку. BLAKE2b hash

Использование

$result = ParagonIE_Sodium_File::generichash( $filePath, $key, $outputLength );
$filePath(строка) (обязательный)
Absolute path to a file on the filesystem
$key(строка/null)
BLAKE2b key
По умолчанию: ''
$outputLength(число)
Length of hash output
По умолчанию: 32

Код ParagonIE_Sodium_File::generichash() WP 5.5.1

<?php
public static function generichash($filePath, $key = '', $outputLength = 32)
{
    /* Type checks: */
    if (!is_string($filePath)) {
        throw new TypeError('Argument 1 must be a string, ' . gettype($filePath) . ' given.');
    }
    if (!is_string($key)) {
        if (is_null($key)) {
            $key = '';
        } else {
            throw new TypeError('Argument 2 must be a string, ' . gettype($key) . ' given.');
        }
    }
    if (!is_int($outputLength)) {
        if (!is_numeric($outputLength)) {
            throw new TypeError('Argument 3 must be an integer, ' . gettype($outputLength) . ' given.');
        }
        $outputLength = (int) $outputLength;
    }

    /* Input validation: */
    if (!empty($key)) {
        if (self::strlen($key) < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MIN) {
            throw new TypeError('Argument 2 must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes');
        }
        if (self::strlen($key) > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_KEYBYTES_MAX) {
            throw new TypeError('Argument 2 must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes');
        }
    }
    if ($outputLength < ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MIN) {
        throw new SodiumException('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MIN');
    }
    if ($outputLength > ParagonIE_Sodium_Compat::CRYPTO_GENERICHASH_BYTES_MAX) {
        throw new SodiumException('Argument 3 must be at least CRYPTO_GENERICHASH_BYTES_MAX');
    }

    /** @var int $size */
    $size = filesize($filePath);
    if (!is_int($size)) {
        throw new SodiumException('Could not obtain the file size');
    }

    /** @var resource $fp */
    $fp = fopen($filePath, 'rb');
    if (!is_resource($fp)) {
        throw new SodiumException('Could not open input file for reading');
    }
    $ctx = ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outputLength);
    while ($size > 0) {
        $blockSize = $size > 64
            ? 64
            : $size;
        $read = fread($fp, $blockSize);
        if (!is_string($read)) {
            throw new SodiumException('Could not read input file');
        }
        ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $read);
        $size -= $blockSize;
    }

    fclose($fp);
    return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength);
}