略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: hash_hmac_file

2024-03-29

hash_hmac_file

(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)

hash_hmac_file使用 HMAC 方法和给定文件的内容生成带密钥的哈希值

说明

hash_hmac_file(
    string $algo,
    string $filename,
    string $key,
    bool $binary = false
): string|false

参数

algo

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

filename

要进行哈希运算的文件路径,支持 fopen 封装器。

key

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

binary

设置为 true 输出原始二进制数据, 设置为 false 输出小写 16 进制字符串。

返回值

如果 binary 设置为 true, 则返回原始二进制数据表示的信息摘要, 否则返回 16 进制小写字符串格式表示的信息摘要。 如果 algo 参数指定的不是受支持的算法,或者无法读取 filename 给定的文件,则返回 false

更新日志

版本 说明
7.2.0 不再支持非加密的哈希函数(adler32,crc32,crc32b,fnv132,fnv1a32,fnv164,fnv1a64,joaat)。

范例

示例 #1 hash_hmac_file() 例程

<?php
/* 创建一个要计算哈希值的文件 */
file_put_contents('example.txt''The quick brown fox jumped over the lazy dog.');

echo 
hash_hmac_file('md5''example.txt''secret');
?>

以上例程会输出:

7eb2b5c37443418fc77c136dd20e859c

参见

  • hash_hmac_algos() - Return a list of registered hashing algorithms suitable for hash_hmac
  • hash_hmac() - 使用 HMAC 方法生成带有密钥的哈希值
  • hash_file() - 给指定文件的内容生成哈希值
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.hash-hmac-file.php

冷却塔厂家 广告
-- 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3