range

If there were you, the world would be just right

微信小游戏中米大师签名加密用到 HMAC-SHA256 的加密方式,此处做个备注

其他语言生成原理,大致分为这几部分:

1. 获取SHA256实例

2. 生成一个加密key

3. 通过这个加密key初始化SHA256实例

4. 根据提供的字符串,使用此实例进行加密生成hash

4. 最后整体就是转为16进制后再输出字符串

php执行起来就方便多了

function hmacsha256($data,$Key){
    $hash = hash_hmac("sha256",$data,$Key,true);
    # 转换为16进制值
    return bin2hex($hash);
}