lyoshenka / php-hmac
A generic HMAC function that can be used with any hash
v1.0
2016-08-29 13:26 UTC
Requires
- php: ^5.4 || ^7.0
This package is not auto-updated.
Last update: 2025-01-01 00:38:22 UTC
README
A generic HMAC function that can be used with any hash
Install
composer install lyoshenka/php-hmac
Use
<?php
require __DIR__.'/vendor/autoload.php';
# Ensure that your hash functions returns raw output (not hex)
$sha256Fn = function($message) { return hash('sha256', $message, true); };
# Look up the block size - https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions
$blockSize = 64; // make sure this in bytes, not bits
# Compute the HMAC digest
$digest = \lyoshenka\hmac("The message text goes here", "secret-key", $sha256Fn, $blockSize);
# Output the digest as a hex string
echo bin2hex($digest) . "\n";
Examples
See examples.php