PHP - mhash_keygen_s2k() Function
The mhash_keygen_s2k() function can generate a derivation key for a given password according to certain MHASH.
Syntax
string mhash_keygen_s2k( int $hash , string $password , string $salt , int $bytes )
The mhash_keygen_s2k() function can generate a key according to the given hash using the user-provided password. This is the Salted S2K algorithm specified in the OpenPGP document.
The mhash_keygen_s2k() function can return the generated key as a string, or false on error.
Example 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"; ?>
Output
G.p8_[ GX<?5jU6<br><br>32 characters<br><br>47a42e709e97381f5f0e97fa5be91520c347a958fc3c3fc8356ab319fc9e5536<br>64 characters
Example 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); ?>
Output
\Xf)UJ6 "OfB]<br><br>185c58662915554accc7d336960022d8d2cfc2f74f9b1e6642195dedce92afc9
php_function_reference.htm
Advertisements