博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用HMAC方法生成带有密钥的哈希值-php
阅读量:3984 次
发布时间:2019-05-24

本文共 1254 字,大约阅读时间需要 4 分钟。

我们有时候需要用到 HMAC-SHA256 算法,就是在哈希算法的基础上加上了密钥,安全性更高。

hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = FALSE ] ) : string

参数
algo
要使用的哈希算法名称,例如:“md5”,“sha256”,“haval160,4” 等。 如何获取受支持的算法清单,请参见 hash_hmac_algos() 函数。

data

要进行哈希运算的消息。

key

使用 HMAC 生成信息摘要时所使用的密钥。

raw_output

设置为 TRUE 输出原始二进制数据, 设置为 FALSE 输出小写 16 进制字符串

class robotReadSkillService{
const READ_SKILL_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; public function checkSign($request) {
$signingContent = 'aaaaaaa'; $signature = $this->signature( $signingContent, self::READ_SKILL_SECRET, $this->getEncryptMethod('TSK-HMAC-SHA256-BASIC') ); return $signature == $authorizationArr['signature']; } public function signature($input, $key, $alg, $raw_output = false) {
if (empty($alg)) {
return ''; } return hash_hmac($alg, $input, $key, $raw_output); } private function getEncryptMethod($string) {
$arr = [ 'TSK-HMAC-SHA256-BASIC' => 'sha256' ]; if (isset($arr[$string])) {
return $arr[$string]; } else {
throw new \Exception('签名算法' . $string . '未定义!'); } }}

转载地址:http://lgxui.baihongyu.com/

你可能感兴趣的文章
[LeetCode BY Python]155. Min Stack
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode By Python]168. Excel Sheet Column Title
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]171. Excel Sheet Column Number
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Mac删除文件&文件夹
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
《Fluent Python》第三章Dictionaries and Sets
查看>>
如何打开ipynb文件
查看>>
[Leetcode BY python ]190. Reverse Bits
查看>>
面试---刷牛客算法题
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>
SVN客户端命令详解
查看>>
Android/Linux 内存监视
查看>>
Linux系统信息查看
查看>>