Commit | Line | Data |
---|---|---|
14d4f286 S |
1 | <?php |
2 | /** | |
3 | * An implementation of the crypt library's SHA512 hash method | |
4 | * | |
5 | * PHP version 5.3 | |
6 | * | |
7 | * @category PHPCryptLib | |
8 | * @package Key | |
9 | * @subpackage Derivation | |
10 | * @author Anthony Ferrara <ircmaxell@ircmaxell.com> | |
11 | * @copyright 2011 The Authors | |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License | |
13 | * @version Build @@version@@ | |
14 | */ | |
15 | ||
16 | namespace CryptLib\Key\Derivation\PBKDF; | |
17 | ||
18 | /** | |
19 | * An implementation of the crypt library's SHA512 hash method | |
20 | * | |
21 | * @category PHPCryptLib | |
22 | * @package Key | |
23 | * @subpackage Derivation | |
24 | * @author Anthony Ferrara <ircmaxell@ircmaxell.com> | |
25 | */ | |
26 | class SHA512 | |
27 | extends \CryptLib\Key\Derivation\AbstractDerivation | |
28 | implements \CryptLib\Key\Derivation\PBKDF | |
29 | { | |
30 | ||
31 | /** | |
32 | * Derive a key from the supplied arguments | |
33 | * | |
34 | * @param string $password The password to derive from | |
35 | * @param string $salt The salt string to use | |
36 | * @param int $iterations The number of iterations to use | |
37 | * @param int $length The size of the string to generate | |
38 | * | |
39 | * @return string The derived key | |
40 | */ | |
41 | public function derive($password, $salt, $iterations, $length) { | |
42 | $salt = substr(str_pad($salt, 16, chr(0)), 0, 16); | |
43 | $salt = '$6$rounds='.$iterations.'$'.$salt; | |
44 | return crypt($password, $salt); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Get the signature for this implementation | |
49 | * | |
50 | * This should include all information needed to build the same isntance | |
51 | * later. | |
52 | * | |
53 | * @return string The signature for this instance | |
54 | */ | |
55 | public function getSignature() { | |
56 | return 'sha512'; | |
57 | } | |
58 | ||
59 | } | |
60 |