跳到主要内容

计算字符串的 HMAC-SHA256 哈希值 (string.hmac_sha256)

声明

hexHash = string.hmac_sha256(data, key)

参数

  • data
    字符串型,用于计算哈希的数据内容
  • key
    字符串型,HMAC 算法使用的密钥

返回值

  • hexHash
    字符串型,返回 HMAC-SHA256 校验值的 16 进制小写文本

说明

使用 HMAC-SHA256 算法对任意字符串(或二进制数据)计算带密钥的哈希摘要

示例

local signature = string.hmac_sha256('hello world', 'secret')
sys.alert(signature) -- 输出 "734cc62f32841568f45715aeb9f4d7891324e6d948e4c6c60c0621cdac48623a"

:上述代码中使用了非本章函数 sys.alert