2017 © Pedro Peláez
 

library php-hmac

A generic HMAC function that can be used with any hash

image

lyoshenka/php-hmac

A generic HMAC function that can be used with any hash

  • Friday, November 25, 2016
  • by lyoshenka
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

php-hmac

A generic HMAC function that can be used with any hash, (*1)

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, (*2)

References

  • https://tools.ietf.org/html/rfc2104
  • https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
  • https://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions

The Versions

25/11 2016

dev-master

9999999-dev https://github.com/lyoshenka/php-hmac

A generic HMAC function that can be used with any hash

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

hmac hash

29/08 2016

v1.0

1.0.0.0 https://github.com/lyoshenka/php-hmac

A generic HMAC function that can be used with any hash

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0

 

hmac hash