Skip to content

Very simple PHP object wrapper for HMAC-based hash.

License

Notifications You must be signed in to change notification settings

DeSmart/php-hmac

Repository files navigation

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.

About

Very simple PHP object wrapper for HMAC-based hash.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages