PHP Function Reference

PHP - Hash



Message Digest (hash) engine allows direct or incremental processing of arbitrary length messages using a variety of hashing algorithms.

Installation

As of PHP 5.1.2, the Hash extension is bundled and compiled into PHP by default.

It may be explicitly disabled by using the --disable-hash switch to configure. Earlier versions of PHP may incorporate the Hash extension by installing the PECL module.

As of PHP 7.4.0, the Hash extension is a core PHP extension, so it is always enabled.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

PHP HashContext Class

Class Description
HashContext The HashContext class.
MethodsDescription
__construct() Private constructor to disallow direct instantiation.

PHP Hash Functions

FunctionsDescription
hash() Generates a hash value (message digest).
hash_algos() Returns a list of registered hashing algorithms.
hash_copy() Copies hashing context.
hash_equals() Timing attack safe string comparison.
hash_file() Generates a hash value using the contents of a given file.
hash_final() Finalizes an incremental hash and return resulting digest.
hash_hkdf() Generates a HKDF key derivation of a supplied key input.
hash_hmac() Generates a keyed hash value using the HMAC method.
hash_hmac_algos() Return a list of registered hashing algorithms suitable for hash_hmac().
hash_hmac_file() Generates a keyed hash value using the HMAC method and the contents of a given file.
hash_init() Initializes an incremental hashing context.
hash_pbkdf2() Generates a PBKDF2 key derivation of a supplied password.
hash_update() Pumps data into an active hashing context.
hash_update_file() Pumps data into an active hashing context from a file.
hash_update_stream() Pumps data into an active hashing context from an open stream.

PHP Hash Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

HASH_HMAC (int)

Optional flag for hash_init(). Indicates that the HMAC digest-keying algorithm should be applied to the current hashing context.