Php/docs/function.hash-hmac
来自菜鸟教程
hash_hmac
(PHP 5 >= 5.1.2, PHP 7, PECL hash >= 1.1)
hash_hmac — 使用 HMAC 方法生成带有密钥的哈希值
说明
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 进制字符串。
返回值
如果 raw_output 设置为 true, 则返回原始二进制数据表示的信息摘要,
否则返回 16 进制小写字符串格式表示的信息摘要。
如果 algo 参数指定的不是受支持的算法,返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| 7.2.0 | 不再支持非加密的哈希函数(adler32,crc32,crc32b,fnv132,fnv1a32,fnv164,fnv1a64,joaat)。 |
范例
Example #1 hash_hmac() 例程
<?phpecho hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');?>
以上例程会输出:
b8e7ae12510bdfb1812e463a7f086122cf37e4f7
参见
- hash() - 生成哈希值 (消息摘要)
- hash_hmac_algos() - Return a list of registered hashing algorithms suitable for hash_hmac
- hash_init() - 初始化增量哈希运算上下文
- hash_hmac_file() - 使用 HMAC 方法和给定文件的内容生成带密钥的哈希值