codecamp

PHP8 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 进制小写字符串格式表示的信息摘要。如果无法读取文件 filename,则返回 false。

错误/异常 

如果 algo 未知或非加密散列函数,则抛出 ValueError 异常。

更新日志 

版本说明
8.0.0如果 algo 未知或非加密散列函数,现在抛出 ValueError 异常,之前返回 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('sha256', 'example.txt', 'secret');
?>

以上示例会输出:

9c5c42422b03f0ee32949920649445e417b2c634050833c5165704b825c2a53b

参见 

  • hash_hmac_algos() - 返回适用于 hash_hmac 的已注册散列算法列表
  • hash_hmac() - 使用 HMAC 方法生成带有密钥的散列值
  • hash_file() - 给指定文件的内容生成散列值


PHP8 hash_hmac_algos
PHP8 hash_hmac
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

PHP8 语言参考

PHP8 函数参考

PHP8 影响 PHP 行为的扩展

PHP8 Componere

PHP8 安装/配置

PHP8 外部函数接口

PHP8 选项和信息

PHP8 选项/信息 函数

PHP8 Windows Cache for PHP

PHP8 WinCache 函数

PHP8 Yac

PHP8 身份认证服务

PHP8 Radius 函数

PHP8 压缩与归档扩展

PHP8 Phar

PHP8 Zip

PHP8 ZipArchive 类

PHP8 加密扩展

PHP8 OpenSSL

PHP8 OpenSSL 函数

PHP8 Sodium 函数

PHP8 数据库扩展

PHP8 针对各数据库系统对应的扩展

PHP8 CUBRID 函数

PHP8 Firebird/InterBase

PHP8 Firebird/InterBase函数

PHP8 MongoDB介绍驱动程序体系结构和特殊功能

PHP8 MongoDB\Driver\Command 类

PHP8 MongoDB\Driver\Query 类

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }