add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Key / Derivation / PBKDF / SHA256.php
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 * PHP version 5.3
22 *
23 * @category PHPCryptLib
24 * @package Key
25 * @subpackage Derivation
26 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
27 */
28 class SHA256
29 extends \CryptLib\Key\Derivation\AbstractDerivation
30 implements \CryptLib\Key\Derivation\PBKDF
31 {
32
33 /**
34 * Derive a key from the supplied arguments
35 *
36 * @param string $password The password to derive from
37 * @param string $salt The salt string to use
38 * @param int $iterations The number of iterations to use
39 * @param int $length The size of the string to generate
40 *
41 * @return string The derived key
42 */
43 public function derive($password, $salt, $iterations, $length) {
44 $salt = substr(str_pad($salt, 16, chr(0)), 0, 16);
45 $salt = '$5$rounds='.$iterations.'$'.$salt;
46 return crypt($password, $salt);
47 }
48
49 /**
50 * Get the signature for this implementation
51 *
52 * This should include all information needed to build the same isntance
53 * later.
54 *
55 * @return string The signature for this instance
56 */
57 public function getSignature() {
58 return 'sha256';
59 }
60
61 }
62