Speed up development with full-stack environments for every branch.

Learn More

Generate a hash and a key using MHASH_SHA1 [PHP]

103 Runs 531 Views 157 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php
/*
 * PHP mhash - generate a hash and a key using MHASH_SHA1
 */
$input = "A random input text";

//Computes hash
//string mhash ( int $hash , string $data [, string $key ] )
$hash = mhash(MHASH_SHA1, $input);
//The return value is as hex
echo "The hash is " . bin2hex($hash) . "<br />\n";

//Generates a key according to the given hash, using an user provided input. 
//string mhash_keygen_s2k ( int $hash , string $password , string $salt , int $bytes )
$key = mhash_keygen_s2k(MHASH_SHA1, $input, "randomsalt", 16) ;
//The return value is as hex
echo "The key is " . bin2hex($key) . "<br />\n";
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).