代码初始化
This commit is contained in:
31
extend/Yzh/Utils/Hmac.php
Normal file
31
extend/Yzh/Utils/Hmac.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Yzh\Utils;
|
||||
|
||||
class Hmac
|
||||
{
|
||||
protected $mode = "sha256";
|
||||
protected $app_key;
|
||||
|
||||
/**
|
||||
* @param string $appKey
|
||||
*/
|
||||
public function __construct($appKey)
|
||||
{
|
||||
$this->app_key = $appKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param string $key
|
||||
*/
|
||||
public function sign($data): string
|
||||
{
|
||||
return hash_hmac($this->mode, $data, $this->app_key);
|
||||
}
|
||||
|
||||
public function verify($data, $sign)
|
||||
{
|
||||
return $this->sign($data) == $sign;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user