Hash 函数 业 ,精于勤 荒于嬉.

Hash 函数 hash_algos 返回已注册的哈希算法列表

发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数

      示例1
<?php 
print_r(hash_algos());
?>

阅读全文 »

Hash 函数 hash_copy 拷贝哈希运算上下文

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
$context = hash_init("md5");
hash_update($context, "data");
/* 拷贝上下文资源以便继续使用 */
$copy_context = hash_copy($context);
echo hash_final($context), "\n";
hash_update($copy_context, "data");
echo hash_final($copy_context), "\n";
?>

阅读全文 »

Hash 函数 hash_equals 可防止时序攻击的字符串比较

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
$expected  = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$correct   = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$incorrect = crypt('apple', '$2a$07$usesomesillystringforsalt$');
var_dump(hash_equals($expected, $correct));
var_dump(hash_equals($expected, $incorrect));
?>

阅读全文 »

Hash 函数 hash_file 给指定文件的内容生成哈希值

发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数

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

阅读全文 »

Hash 函数 hash_final 结束增量哈希,并且返回摘要结果

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
$ctx = hash_init('sha1');
hash_update($ctx, 'The quick brown fox jumped over the lazy dog.');
echo hash_final($ctx);
?>

阅读全文 »

Hash 函数 hash_hkdf Generate a HKDF key derivation of a supplied key input

发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数

      示例1
<?php 
// Generate a random key, and salt to strengthen it during derivation.$inputKey = random_bytes(32);
$salt = random_bytes(16);
// Derive a pair of separate keys, using the same input created above.$encryptionKey = hash_hkdf('sha256', $inputKey, 32, 'aes-256-encryption', $salt);
$authenticationKey = hash_hkdf('sha256', $inputKey, 32, 'sha-256-authentication', $salt);
var_dump($encryptionKey !== $authenticationKey);
 // bool(true)?>

阅读全文 »

Hash 函数 hash_hmac_algos Return a list of registered hashing algorithms suitable for hash_hmac

发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数

      示例1
<?php 
print_r(hash_hmac_algos());


阅读全文 »

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

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
/* 创建一个要计算哈希值的文件 */
file_put_contents('example.txt', 'The quick brown fox jumped over the lazy dog.');
echo hash_hmac_file('md5', 'example.txt', 'secret');
?>

阅读全文 »

Hash 函数 hash_hmac 使用 HMAC 方法生成带有密钥的哈希值

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
echo hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');
?>

阅读全文 »

Hash 函数 hash_init 初始化增量哈希运算上下文

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
$ctx = hash_init('md5');
hash_update($ctx, 'The quick brown fox ');
hash_update($ctx, 'jumped over the lazy dog.');
echo hash_final($ctx);
?>

阅读全文 »

Hash 函数 hash_pbkdf2 生成所提供密码的 PBKDF2 密钥导出

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
$password = "password";
$iterations = 1000;
// 使用 openssl_random_pseudo_bytes(),random_bytes(),或者其他合适的随机数生成函数// 来生成随机初始向量$salt = openssl_random_pseudo_bytes(16, MCRYPT_DEV_URANDOM);
$hash = hash_pbkdf2("sha256", $password, $salt, $iterations, 20);
echo $hash;
?>

阅读全文 »

Hash 函数 hash_update_file 从文件向活跃的哈希运算上下文中填充数据

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

hash_update_file

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

hash_update_file从文件向活跃的哈希运算上下文中填充数据

说明

hash_update_file(HashContext $hcontext, string $filename, resource $scontext = null): bool

参数

hcontext

hash_init() 函数返回的哈希运算上下文。

filename

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

scontext

stream_context_create() 函数返回的流上下文。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
7.2.0 接收参数从资源类型修改为 HashContext 对象类型。

参见

阅读全文 »

Hash 函数 hash_update_stream 从打开的流向活跃的哈希运算上下文中填充数据

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
$fp = tmpfile();
fwrite($fp, 'The quick brown fox jumped over the lazy dog.');
rewind($fp);
$ctx = hash_init('md5');
hash_update_stream($ctx, $fp);
echo hash_final($ctx);
?>

阅读全文 »

Hash 函数 hash_update 向活跃的哈希运算上下文中填充数据

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

hash_update

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

hash_update向活跃的哈希运算上下文中填充数据

说明

hash_update(HashContext $context, string $data): bool

参数

context

hash_init() 函数返回的哈希运算上下文。

data

要向哈希摘要中追加的数据。

返回值

返回 true

更新日志

版本 说明
7.2.0 接收参数从资源类型修改为 HashContext 对象类型。

参见

阅读全文 »

Hash 函数 hash 生成哈希值 (消息摘要)

发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数

      示例1
<?php 
echo hash('ripemd160', 'The quick brown fox jumped over the lazy dog.');
?>

      示例2
<?php 
function old_tiger($data = "", $width=192, $rounds = 3) {
    return substr(        implode(            array_map(                function ($h) {
                    return str_pad(bin2hex(strrev($h)), 16, "0");
                }
,                str_split(hash("tiger192,$rounds", $data, true), 8)            )        ),        0, 48-(192-$width)/4    );
}
echo hash('tiger192,3', 'a-string'), PHP_EOL;
echo old_tiger('a-string'), PHP_EOL;
?>

阅读全文 »

全部博文(1580)
集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。