openssl_pbkdf2

FunctionMisc changes in PHP 8.2

Generates a PKCS5 v2 PBKDF2 string.

PHP 5.3-5.4
PHP 5.5
Added
PHP 5.6
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2
Changed
PHP 8.3
PHP 8.4
PHP 8.5
PHP 8.6

openssl_pbkdf2 Function synopsis

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

Parameters

$password

Typestring

Password from which the derived key is generated.

$salt

Typestring

$key_length

Typeint

Length of desired output key.

$iterations

Typeint

The number of iterations desired. NIST recommends at least 1,000. As of 2023, OWASP recommends 600,000 iterations for PBKDF2-HMAC-SHA256 and 210,000 for PBKDF2-HMAC-SHA512.

$digest_algo

OptionalTypestringDefault value"sha1"

Optional hash or digest algorithm from openssl_get_md_methods. Defaults to SHA-1. It is recommended to set it to SHA-256 or SHA-512.

Return value

Typestring|false

Returns raw binary string or false on failure.

Changes to the openssl_pbkdf2 Function

PHP 8.2

PHP 8.0

  • Return type added: string|false
  • Parameter type added for parameter #1 ($password): string
  • Parameter type added for parameter #2 ($salt): string
  • Parameter type added for parameter #3 ($key_length): int
  • Parameter type added for parameter #4 ($iterations): int
  • Parameter name of parameter #5 changed: $digest_algorithm to $digest_algo
  • Parameter type added for parameter #5 ($digest_algo): string
  • Parameter default value added for position #5 ($digest_algo): "sha1"
  openssl_pbkdf2(
-     $password,
+     string $password,
-     $salt,
+     string $salt,
-     $key_length,
+     int $key_length,
-     $iterations,
+     int $iterations,
-     $digest_algorithm
+     string $digest_algo = "sha1"
-   )
+   ): string|false

PHP 5.5

  • Function added

openssl_pbkdf2 Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported No
PHP 5.3Unsupported No