Hash 函数 业 ,精于勤 荒于嬉.
- Hash 函数 hash_algos 返回已注册的哈希算法列表
-
发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
print_r(hash_algos());
3
?>
- Hash 函数 hash_copy 拷贝哈希运算上下文
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
$context
= hash_init(
"md5"
);
3
hash_update(
$context
,
"data"
);
4
/* 拷贝上下文资源以便继续使用 */
5
$copy_context
= hash_copy(
$context
);
6
echo
hash_final(
$context
),
"\n"
;
7
hash_update(
$copy_context
,
"data"
);
8
echo
hash_final(
$copy_context
),
"\n"
;
9
?>
- Hash 函数 hash_equals 可防止时序攻击的字符串比较
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
$expected
= crypt(
'12345'
,
'$2a$07$usesomesillystringforsalt$'
);
3
$correct
= crypt(
'12345'
,
'$2a$07$usesomesillystringforsalt$'
);
4
$incorrect
= crypt(
'apple'
,
'$2a$07$usesomesillystringforsalt$'
);
5
var_dump(hash_equals(
$expected
,
$correct
));
6
var_dump(hash_equals(
$expected
,
$incorrect
));
7
?>
- Hash 函数 hash_file 给指定文件的内容生成哈希值
-
发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
/* 创建一个要计算哈希值的文件 */
3
file_put_contents
(
'example.txt'
,
'The quick brown fox jumped over the lazy dog.'
);
4
echo
hash_file(
'md5'
,
'example.txt'
);
5
?>
- Hash 函数 hash_final 结束增量哈希,并且返回摘要结果
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
$ctx
= hash_init(
'sha1'
);
3
hash_update(
$ctx
,
'The quick brown fox jumped over the lazy dog.'
);
4
echo
hash_final(
$ctx
);
5
?>
- Hash 函数 hash_hkdf Generate a HKDF key derivation of a supplied key input
-
发表日期:2021-07-01 08:55:15 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
// Generate a random key, and salt to strengthen it during derivation.$inputKey = random_bytes(32);
3
$salt
= random_bytes(16);
4
// Derive a pair of separate keys, using the same input created above.$encryptionKey = hash_hkdf('sha256', $inputKey, 32, 'aes-256-encryption', $salt);
5
$authenticationKey
= hash_hkdf(
'sha256'
,
$inputKey
, 32,
'sha-256-authentication'
,
$salt
);
6
var_dump(
$encryptionKey
!==
$authenticationKey
);
7
// 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
1
<?php
2
print_r(hash_hmac_algos());
- Hash 函数 hash_hmac_file 使用 HMAC 方法和给定文件的内容生成带密钥的哈希值
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
/* 创建一个要计算哈希值的文件 */
3
file_put_contents
(
'example.txt'
,
'The quick brown fox jumped over the lazy dog.'
);
4
echo
hash_hmac_file(
'md5'
,
'example.txt'
,
'secret'
);
5
?>
- Hash 函数 hash_hmac 使用 HMAC 方法生成带有密钥的哈希值
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
echo
hash_hmac(
'ripemd160'
,
'The quick brown fox jumped over the lazy dog.'
,
'secret'
);
3
?>
- Hash 函数 hash_init 初始化增量哈希运算上下文
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
$ctx
= hash_init(
'md5'
);
3
hash_update(
$ctx
,
'The quick brown fox '
);
4
hash_update(
$ctx
,
'jumped over the lazy dog.'
);
5
echo
hash_final(
$ctx
);
6
?>
- Hash 函数 hash_pbkdf2 生成所提供密码的 PBKDF2 密钥导出
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
$password
=
"password"
;
3
$iterations
= 1000;
4
// 使用 openssl_random_pseudo_bytes(),random_bytes(),或者其他合适的随机数生成函数// 来生成随机初始向量$salt = openssl_random_pseudo_bytes(16, MCRYPT_DEV_URANDOM);
5
$hash
= hash_pbkdf2(
"sha256"
,
$password
,
$salt
,
$iterations
, 20);
6
echo
$hash
;
7
?>
- 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_init() - 初始化增量哈希运算上下文
- hash_update() - 向活跃的哈希运算上下文中填充数据
- hash_update_stream() - 从打开的流向活跃的哈希运算上下文中填充数据
- hash_final() - 结束增量哈希,并且返回摘要结果
- hash() - 生成哈希值 (消息摘要)
- hash_file() - 给指定文件的内容生成哈希值
-
- Hash 函数 hash_update_stream 从打开的流向活跃的哈希运算上下文中填充数据
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
$fp
= tmpfile();
3
fwrite(
$fp
,
'The quick brown fox jumped over the lazy dog.'
);
4
rewind
(
$fp
);
5
$ctx
= hash_init(
'md5'
);
6
hash_update_stream(
$ctx
,
$fp
);
7
echo
hash_final(
$ctx
);
8
?>
- 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返回值
返回
true
。更新日志
版本 说明 7.2.0 接收参数从资源类型修改为 HashContext 对象类型。 参见
- hash_init() - 初始化增量哈希运算上下文
- hash_update_file() - 从文件向活跃的哈希运算上下文中填充数据
- hash_update_stream() - 从打开的流向活跃的哈希运算上下文中填充数据
- hash_final() - 结束增量哈希,并且返回摘要结果
- Hash 函数 hash 生成哈希值 (消息摘要)
-
发表日期:2021-07-01 08:55:16 | 来源: | 分类:Hash 函数
-
示例1
1
<?php
2
echo
hash(
'ripemd160'
,
'The quick brown fox jumped over the lazy dog.'
);
3
?>
示例2
01
<?php
02
function
old_tiger(
$data
=
""
,
$width
=192,
$rounds
= 3) {
03
return
substr
( implode(
array_map
(
function
(
$h
) {
04
return
str_pad
(bin2hex(
strrev
(
$h
)), 16,
"0"
);
05
}
06
,
str_split
(hash(
"tiger192,$rounds"
,
$data
, true), 8) ) ), 0, 48-(192-
$width
)/4 );
07
}
08
echo
hash(
'tiger192,3'
,
'a-string'
), PHP_EOL;
09
echo
old_tiger(
'a-string'
), PHP_EOL;
10
?>
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)