Package provides a very simple object wrapper for HMAC-based hash.
To install the package via Composer, simply run the following command:
composer require desmart/php-hmac
Create a HMAC object:
$hmac = HMAC::create('hash-key', 'string to hash'); // use default hashing algorithm (SHA256)
$hmac = HMAC::create('hash-key', 'string to hash', 'sha512'); // use SHA512 as hashing algorithm
$hmac = HMAC::create('hash-key', 'string to hash', 'sha512', true); // use raw output (instead of lowercase hexits)
Create a HMAC object from hash:
$hmac = HMAC::createFromHash('hash-key', 'hash');
Compare two HMAC objects:
$hmac = HMAC::create('hash-key', 'string to hash');
$otherHmac = HMAC::createFromHash('hash-key', 'hashed string');
$hmac->isEqual($otherHmac);
By default, a HMAC hash will be produced using a SHA256 algorithm. It can be changed:
HMAC::$defaultHashingAlgo = 'sha512';
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.