lyoshenka / php-hmac
一个通用的HMAC函数,可以与任何哈希函数一起使用
v1.0
2016-08-29 13:26 UTC
Requires
- php: ^5.4 || ^7.0
This package is not auto-updated.
Last update: 2024-09-24 23:13:13 UTC
README
一个通用的HMAC函数,可以与任何哈希函数一起使用
安装
composer install lyoshenka/php-hmac
使用
<?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.php