PHP 8.3.4 Released!

openssl_pbkdf2

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

openssl_pbkdf2PKCS5 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 は少なくとも10000を推奨しています.

digest_algo

オプションのハッシュまたはダイジェストアルゴリズム。 アルゴリズムの一覧は、openssl_get_md_methods() で得られます。 デフォルトは SHA-1 です。

戻り値

生のバイナリ文字列を返します。失敗した場合に false を返します。

例1 openssl_pbkdf2() の例

<?php
$password
= 'password';
$salt = openssl_random_pseudo_bytes(16);
$keyLength = 20;
$iterations = 600000;
$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 1 note

up
0
McGlockenshire
9 years ago
Despite the manual claiming that this is available in PHP 5.5 and above, this function wasn't made available in my local install.

I expect that having a prehistoric OpenSSL library version installed is the likely culprit.

If you're using PHP 5.5 and don't have this function available in your OpenSSL extension, look at the functionally equivalent hash_pbkdf2 function instead.
To Top