PHP - mhash_keygen_s2k() 函数



mhash_keygen_s2k() 函数可以根据特定的 MHASH 生成给定密码的派生密钥。

语法

string mhash_keygen_s2k( int $hash , string $password , string $salt , int $bytes )

mhash_keygen_s2k() 函数可以使用用户提供的密码根据给定的哈希生成密钥。这是 OpenPGP 文档中指定的加盐 S2K 算法。

mhash_keygen_s2k() 函数可以将生成的密钥作为字符串返回,或者在出错时返回 false。

示例 1

<?php
   $hash03 = MHASH_SHA256;

   $passw = "kda553nh4";
   $salt = "35t4akiiih";
   $byts = 32;

   $resultr03 = mhash_keygen_s2k($hash03, $passw, $salt, $byts);
   $chrr03 = strlen($resultr03);

   $resulth03 = bin2hex($resultr03);
   $chrh03 = strlen($resulth03);

   echo $resultr03 . "<br><br>" . $chrr03 . " characters<br><br>"  . $resulth03 . "<br>" . $chrh03 . " characters";
?>

输出

G�.p��8_��[� �G�X�<?�5j���U6<br><br>32 characters<br><br>47a42e709e97381f5f0e97fa5be91520c347a958fc3c3fc8356ab319fc9e5536<br>64 characters

示例 2

<?php
   $hash04 = MHASH_SHA256;

   $passw = "kdap455W07D";
   $salt = openssl_random_pseudo_bytes(32);

   $byts = 32;
   $result04 = mhash_keygen_s2k($hash04, $passw, $salt, $byts);

   echo $result04 . "<br><br>" . bin2hex($result04);
?>

输出

\Xf)UJ���6� "�����O�fB]���<br><br>185c58662915554accc7d336960022d8d2cfc2f74f9b1e6642195dedce92afc9
php_function_reference.htm
广告