哈希信息摘要¶
属性 | 值 |
---|---|
命名空间 | fize\security |
类名 | Hash |
方法: |
---|
方法名 | 说明 |
---|---|
__construct() | 构造 |
algos() | 返回已注册的哈希算法列表 |
copy() | 拷贝当前哈希运算上下文 |
equals() | 可防止时序攻击的字符串比较 |
file() | 使用给定文件的内容生成哈希值 |
final() | 结束增量哈希,并且返回摘要结果 |
hmacFile() | 使用 HMAC 方法和给定文件的内容生成带密钥的哈希值 |
hmac() | 使用 HMAC 方法生成带有密钥的哈希值 |
init() | 初始化增量哈希运算上下文 |
pbkdf2() | 生成所提供密码的 PBKDF2 密钥导出 |
updateFile() | 从文件向活跃的哈希运算上下文中填充数据 |
updateStream() | 从打开的流向活跃的哈希运算上下文中填充数据 |
update() | 向活跃的哈希运算上下文中填充数据 |
方法¶
__construct()¶
构造
public function __construct (
string $algo,
int $options = 0,
string $key = null
)
参数: |
|
---|
参数 `$algo` :
例如:"md5","sha256","haval160,4" 等
参数 `$options` :
目前仅支持一个选项:HASH_HMAC
参数 `$key` :
使用此参数传入进行 HMAC 哈希运算时的共享密钥。
copy()¶
拷贝当前哈希运算上下文
public function copy (
bool $clone = true
) : mixed
参数: |
|
---|
参数 `$clone` :
如果 $clone 为 true 则返回的是克隆的 Hash 类而非哈希运算上下文
equals()¶
可防止时序攻击的字符串比较
public static function equals (
string $known_string,
string $user_string
) : bool
参数: |
|
---|
非常重要的一点是,用户提供的字符串必须是第二个参数。
file()¶
使用给定文件的内容生成哈希值
public static function file (
string $algo,
string $filename,
bool $raw_output = false
) : string
参数: |
|
---|
参数 `$algo` :
例如:"md5","sha256","haval160,4" 等。
参数 `$filename` :
支持 fopen 封装器。
参数 `$raw_output` :
设置为 TRUE,输出格式为原始的二进制数据。 设置为 FALSE,输出小写的 16 进制字符串。
final()¶
结束增量哈希,并且返回摘要结果
public function final (
bool $raw_output = false
) : string
参数: |
|
---|
参数 `$raw_output` :
设置为 TRUE,输出格式为原始的二进制数据。 设置为 FALSE,输出小写的 16 进制字符串。
hmacFile()¶
使用 HMAC 方法和给定文件的内容生成带密钥的哈希值
public static function hmacFile (
string $algo,
string $filename,
string $key,
bool $raw_output = false
) : string
参数: |
|
---|
参数 `$algo` :
例如:"md5","sha256","haval160,4" 等.
参数 `$filename` :
支持 fopen 封装器。
参数 `$raw_output` :
设置为 TRUE,输出格式为原始的二进制数据。 设置为 FALSE,输出小写的 16 进制字符串。
hmac()¶
使用 HMAC 方法生成带有密钥的哈希值
public static function hmac (
string $algo,
string $data,
string $key,
bool $raw_output = false
) : string
参数: |
|
---|
参数 `$algo` :
例如:"md5","sha256","haval160,4" 等。
参数 `$raw_output` :
设置为 TRUE,输出格式为原始的二进制数据。 设置为 FALSE,输出小写的 16 进制字符串。
init()¶
初始化增量哈希运算上下文
public static function init (
string $algo,
int $options = 0,
string $key = null
) : resource
参数: |
|
||||||||
---|---|---|---|---|---|---|---|---|---|
返回值: | 返回哈希运算上下文资源 |
参数 `$algo` :
例如:"md5","sha256","haval160,4" 等。
参数 `$options` :
目前仅支持一个选项:HASH_HMAC
参数 `$key` :
当 options 参数为 HASH_HMAC 时, 使用此参数传入进行 HMAC 哈希运算时的共享密钥。
pbkdf2()¶
生成所提供密码的 PBKDF2 密钥导出
public static function pbkdf2 (
string $algo,
string $password,
string $salt,
int $iterations,
int $length = 0,
bool $raw_output = false
) : string
参数: |
|
---|
参数 `$algo` :
例如:"md5","sha256","haval160,4" 等。
参数 `$salt` :
这个值应该是随机生成的。
参数 `$length` :
默认0,则使用所选算法的完整输出大小。
参数 `$raw_output` :
设置为 TRUE,输出格式为原始的二进制数据。 设置为 FALSE,输出小写的 16 进制字符串。
updateFile()¶
从文件向活跃的哈希运算上下文中填充数据
public function updateFile (
string $filename,
resource $scontext = null
) : bool
参数: |
|
---|
参数 `$filename` :
支持 fopen 封装器。
参数 `$scontext` :
由 stream_context_create() 函数返回的流上下文。
updateStream()¶
从打开的流向活跃的哈希运算上下文中填充数据
public function updateStream (
resource $handle,
int $length = -1
) : int
参数: |
|
||||||
---|---|---|---|---|---|---|---|
返回值: | 从 handle 向哈希运算上下文中实际填充的字节数量 |
参数 `$length` :
-1 表示全部返回。
update()¶
向活跃的哈希运算上下文中填充数据
public function update (
string $data
) : bool
参数: |
|
---|