The php Function Sodium_Crypto_Generichash
php function sodium_crypto_generichash
PHP has many built-in functions to do the job of common programming tasks. However, it also has a number of higher-order functions that can make your life easier when doing more advanced work in the language. There are two main characteristics that make a higher-order function: it takes one or more functions as input and it returns a function as its output. The latter is especially useful for handling things like callable parameters, closures, lambda functions, and more. There's a special keyword that's easy to identify as being a higher-order function: it uses the keyword callable.
The php function sodium_crypto_generichash takes a random string as its argument, generates a hash of that string using a cryptographically secure pseudo-random number generator, and then returns the result of that hash to the caller. You can use it to protect access to a resource without storing any data in the database, verify the authenticity of a message, and more.
The function is part of the libsodium extension, which provides tools for doing cryptography in a simple way. It is a modern library (v1 was released in 2014), portable, and easy to use. It's a great alternative to older libraries, such as mcrypt and OpenSSL, which provide asymmetric encryption but require key and nonce lengths that can be very difficult to calculate. You can get the libsodium extension from PECL, and it's included in the core since PHP 7.2. You can see if it's installed by calling phpinfo().