-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.php
More file actions
60 lines (54 loc) · 1.59 KB
/
Hash.php
File metadata and controls
60 lines (54 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php // vim:ts=3:sts=3:sw=3:et:
/**
* Hash module
*
* PHP Version 5
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @copyright 2005-2011 Bryan C. Geraghty
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
/**
* This hash "module" is really just an implementation wrapper for various
* mhash/mcrypt functions.
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
class MindFrame2_Hash
{
/**
* Generates and authentication token that can be used to verify sessions.
* For salt values, the generateSalt() function can be used.
*
* @param string $key Key to be used to create the hash from
* @param string $salt A unique random value for this hash
*
* @return string
*/
public static function generateToken($key, $salt, $bytes)
{
return mhash_keygen_s2k(MHASH_SHA256, $key, $salt, $bytes);
}
/**
* Generates a random string containing the number of specified bytes
*
* @param int $bytes Number of bytes to generate
*
* @return string
*/
public static function generateSalt($bytes)
{
MindFrame2_Core::assertArgumentIsInt($bytes, 1, 'bytes');
$rand = (strtolower(substr(PHP_OS, 0, 3)) == 'win')
? MCRYPT_RAND : MCRYPT_DEV_URANDOM;
$salt = substr(mcrypt_create_iv($bytes, $rand), 0, $bytes);
return $salt;
}
}