openssl_pbkdf2

(PHP 5 >= 5.5.0, PHP 7)

openssl_pbkdf2锟斤拷锟斤拷一锟斤拷 PKCS5 v2 PBKDF2 锟街凤拷锟斤拷

说锟斤拷

openssl_pbkdf2 ( string $password , string $salt , int $key_length , int $iterations [, string $digest_algorithm = "sha1" ] ) : string

openssl_pbkdf2() 锟斤拷锟斤拷 PBKDF2 (Password-Based Key Derivation Function 2), 锟斤拷PKCS5 v2锟叫讹拷锟斤拷锟揭伙拷锟斤拷锟皆匡拷锟斤拷频锟斤拷锟斤拷锟�.

锟斤拷锟斤拷

password

锟斤拷锟斤拷锟斤拷钥锟斤拷锟斤拷锟缴碉拷锟斤拷锟诫。

salt

PBKDF2 锟狡硷拷一锟斤拷锟斤拷锟斤拷锟斤拷64位(8锟街斤拷)锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷

key_length

希锟斤拷锟斤拷锟斤拷锟皆匡拷某锟斤拷取锟�

iterations

锟斤拷要锟侥碉拷锟斤拷锟斤拷锟斤拷 » NIST 锟斤拷锟斤拷锟斤拷锟斤拷10,000锟斤拷.

digest_algorithm

锟斤拷openssl_get_md_methods()锟叫匡拷选锟斤拷散锟叫伙拷摘要锟姐法.默锟斤拷锟斤拷 SHA-1.

锟斤拷锟斤拷值

锟缴癸拷锟斤拷锟斤拷锟斤拷原始锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE.

锟斤拷锟斤拷

Example #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";
?>

锟轿硷拷

  • hash_pbkdf2() - 锟斤拷锟斤拷锟斤拷锟结供锟斤拷锟斤拷锟� PBKDF2 锟斤拷钥锟斤拷锟斤拷
  • openssl_get_md_methods() - 锟斤拷取锟斤拷锟矫碉拷摘要锟姐法