Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

hash_init

Description

The hash_init of Hash for PHP initialize an incremental hashing context.

Syntax

hash_init(
    string $algo,
    int $flags = 0,
    string $key = "",
    array $options = []
): HashContext

Parameters

algo

Name of selected hashing algorithm.

flags

Optional settings for hash generation, currently supports only one option: HASH_HMAC. When specified, the key must be specified.

key

When HASH_HMAC is specified for flags, a shared secret key to be used with the HMAC hashing method must be supplied in this parameter.

options

An array of options for the various hashing algorithms. Currently, only the "seed" parameter is supported by the MurmurHash variants.

Return

Returns a Hashing Context for use with hash_update(), hash_update_stream(), hash_update_file(), and hash_final().

Examples

1 · algo

<?

$algo = 'sha384';

$return = hash_init($algo);

hash_update($return, 'Hello');

echo hash_final($return);

?>
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc

2 · flags key

<?

$algo = 'sha384';
$flags = HASH_HMAC;
$key = 'secret';

$return = hash_init($algo, $flags, $key);

hash_update($return, 'Hello');

echo hash_final($return);

?>
0a18a877cf68b022767a7c9be11d132141ee63272d3fd3110897d3c2c86940ad9f07c758545983c09342845cf19cb4b8

3 · options · empty

<?

$algo = 'sha384';
$flags = 0;
$key = '';
$options = [];

$return = hash_init($algo, $flags, $key, $options);

hash_update($return, 'Hello');

echo hash_final($return);

?>
3519fe5ad2c596efe3e276a6f351b8fc0b03db861782490d45f7598ebd0ab5fd5520ed102f38c4a5ec834e98668035fc

4 · options · seed

<?

$algo = 'murmur3f';
$flags = 0;
$key = '';
$options = ['seed' => 42];

$return = hash_init($algo, $flags, $key, $options);

hash_update($return, 'Hello');

echo hash_final($return);

?>
2365fb86a62c2c3ba0c2a44a316b36e2
HomeMenu