Open In App

PHP mhash_keygen_s2k() Function

The mhash_keygen_s2k() function is an in-built function in PHP which is used to generate a key according to the given hash, using a user-provided password. This is the salted S2K algorithm specified in the OpenPGP document (RFC 2440). This function can be used to compute the checksum, message digests, etc.
A Salt is a random piece of data used to generate the key. To check the key, you must also know the salt, so it is a good idea to append the salt too.

Syntax:



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

Parameter: This function accepts four parameters as mentioned above and described below:

Return Value: This function returns the generated key as a string, or FALSE on error.



Below program illustrates the mhash_keygen_s2k() function in PHP:

Program:




<?php
  
$inputString  = "p4ssw0rd" ;
$salt = "agejkhgeuka";
  
$bytes = "8";
  
// bin2hex is used to convert binary
// to hex string
  
print_r(bin2hex(mhash_keygen_s2k(
      MHASH_MD5, $inputString, $salt, $bytes)));
  
?>

Output:

e2dfb845290aae21
Article Tags :