Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.51 KB

README.md

File metadata and controls

48 lines (36 loc) · 1.51 KB

PHP HMAC #️⃣

Latest version Tests Software License

Package provides a very simple object wrapper for HMAC-based hash.

Installation

To install the package via Composer, simply run the following command:

composer require desmart/php-hmac

Usage

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);

Default hashing algorithm

By default, a HMAC hash will be produced using a SHA256 algorithm. It can be changed:

HMAC::$defaultHashingAlgo = 'sha512';

Changelog

Please see CHANGELOG for more information what has changed recently.

License

The MIT License (MIT). Please see License File for more information.