Hash methods in php: hash_algos(), hash_copy(), hash_equals(), hash_file(), hash_final(), hash_hkdf(), hash_hmac(), hash_init(), hash(), etc.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Hash in php Methods
hash_algos — Returns a list of registered hash algorithms
hash_copy — Copies the hash operation context
hash_equals — String comparison to prevent timing attacks
hash_file — Generate a hash value for the contents of a specified file
hash_final — End incremental hashing and return summary results
hash_hkdf — Generate a HKDF key derivation of a supplied key input
hmac_algos — Return a list of registered hashing algorithms suitable for hash_hmac
hash_hmac_file — Generate a keyed hash value using the HMAC method and the contents of the given file
hash_hmac — Generate hash value with key using HMAC method
hash_init — Initialize incremental hashing context
hash_pbkdf2 — Generates a PBKDF2 key export for the supplied password
hash_update_file — Populates the active hashing context with data from a file
hash_update_stream — Populate data from an open stream into an active hashing context
hash_update — Populate data into an active hashing context
hash — Generate hash value (message digest)
hash_algos()
hash_algos — Return registered hash Algorithm list
Syntax:hash_algos()
Return value: Returns a numerically indexed array containing the names of supported hash algorithms.
hash_copy()
hash_copy — Copy hash operation context
Syntax: hash_copy($context)
$context: The hash operation context returned by the hash_init() function.
Return value: Returns a copy of the hash operation context.
hash_equals()
hash_equals — String comparison that prevents timing attacks
Syntax: hash_equals($known_string, $user_string)
$known_string: a string of known length that needs to be compared
$user_string: a string provided by the user
Return value: Return true when the two strings are equal, otherwise return false.
hash_file()
hash_file — Generate a hash value for the contents of the specified file
Syntax: hash_file($algo,$filename ,$binary = false)
$algo: The name of the hash algorithm to use (for example: "md5", "sha256", "haval160,4", etc.) . You can check the currently supported algorithms in hash_algos().
$filename: URL of the file location to be hashed; supports fopen encapsulation protocol.
$binary: When set to true, original binary data is output. When set to false, a lowercase hexadecimal string is output.
Return value: If binary is set to true, the information summary represented by the original binary data is returned, otherwise the information summary represented by the hexadecimal lowercase string format is returned.
hash_final()
hash_final - End the incremental hash and return the summary result
Syntax: hash_final($context,$ raw_output = false)
$context: The hash operation context resource returned by the hash_init() function.
$raw_output: Set to true, the output format is raw binary data. Set to false to output a lowercase hexadecimal string.
Return value: If raw_output is set to true, the information summary represented by the original binary data is returned, otherwise the information summary represented by the hexadecimal lowercase string format is returned.
hash_init()
hash_init — Initialize the incremental hash operation context
Syntax: hash_init($algo,$options = 0 , $key = null)
$algo: The name of the hash algorithm to be used, for example: "md5", "sha256", "haval160,4", etc. How to get a list of supported algorithms, see hash_algos().
$options: Optional settings for hashing. Currently only one option is supported: HASH_HMAC. When specifying this option, the key parameter must be specified.
$key: When the options parameter is HASH_HMAC, use this parameter to pass in the shared key for HMAC hashing.
Return value: Returns the hash operation context object for use by hash_update(), hash_update_stream(), hash_update_file(), and hash_final() functions.
. . . .
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What are the hash methods in php. For more information, please follow other related articles on the PHP Chinese website!