openssl_pbkdf2

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

openssl_pbkdf2生成一个 PKCS5 v2 PBKDF2 字符串

说明

openssl_pbkdf2(
    string $password,
    string $salt,
    int $key_length,
    int $iterations,
    string $digest_algo = "sha1"
): string|false

openssl_pbkdf2() 计算 PBKDF2 (Password-Based Key Derivation Function 2), 在PKCS5 v2中定义的一个密钥的推导函数.

参数

password

派生密钥所生成的密码。

salt

PBKDF2 推荐一个不少于64位(8字节)的密码盐值。

key_length

希望输出密钥的长度。

iterations

需要的迭代次数 » NIST 建议至少10,000次.

digest_algo

openssl_get_md_methods()中可选的散列或摘要算法.默认是 SHA-1.

返回值

成功,返回原始二进制字符串 或者在失败时返回 false.

范例

示例 #1 openssl_pbkdf2() 示例

<?php
$password
= 'yOuR-pAs5w0rd-hERe';
$salt = openssl_random_pseudo_bytes(12);
$keyLength = 40;
$iterations = 10000;
$generated_key = openssl_pbkdf2($password, $salt, $keyLength, $iterations, 'sha256');
echo
bin2hex($generated_key)."\n";
echo
base64_encode($generated_key)."\n";
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top