add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Key / Factory.php
1 <?php
2 /**
3 * The core Key Factory
4 *
5 * PHP version 5.3
6 *
7 * @category PHPCryptLib
8 * @package Key
9 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
10 * @copyright 2011 The Authors
11 * @license http://www.opensource.org/licenses/mit-license.html MIT License
12 * @version Build @@version@@
13 */
14
15 namespace CryptLib\Key;
16
17 /**
18 * The core Key Factory
19 *
20 * @category PHPCryptLib
21 * @package Key
22 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
23 */
24 class Factory extends \CryptLib\Core\AbstractFactory {
25
26 /**
27 * @var array An array of KDF class implementations
28 */
29 protected $kdf = array();
30
31 /**
32 * @var array An array of PBKDF class implementations
33 */
34 protected $pbkdf = array();
35
36 /**
37 * @var array An array of symmetric key generator implementations
38 */
39 protected $symmetricGenerators = array();
40
41 /**
42 * Construct the instance, loading the core implementations
43 *
44 * @return void
45 */
46 public function __construct() {
47 $this->loadPBKDF();
48 $this->loadKDF();
49 //$this->loadSymmetricGenerators();
50 }
51
52 public function getKDF($name = 'kdf3', array $options = array()) {
53 if (isset($this->kdf[$name])) {
54 $class = $this->kdf[$name];
55 return new $class($options);
56 }
57 throw new \InvalidArgumentException('Unsupported KDF');
58 }
59
60 public function getPBKDF($name = 'pbkdf2', array $options = array()) {
61 if (isset($this->pbkdf[$name])) {
62 $class = $this->pbkdf[$name];
63 return new $class($options);
64 }
65 throw new \InvalidArgumentException('Unsupported PBKDF');
66 }
67
68 public function getPBKDFFromSignature($signature) {
69 list ($name, $hash) = explode('-', $signature, 2);
70 return $this->getPBKDF($name, array('hash' => $hash));
71 }
72
73 public function getSymmetricKeyGenerator() {
74 }
75
76 public function registerKDF($name, $class) {
77 $this->registerType(
78 'kdf',
79 __NAMESPACE__ . '\\Derivation\\KDF',
80 $name,
81 $class
82 );
83 }
84
85 public function registerPBKDF($name, $class) {
86 $this->registerType(
87 'pbkdf',
88 __NAMESPACE__ . '\\Derivation\\PBKDF',
89 $name,
90 $class
91 );
92 }
93
94 protected function loadKDF() {
95 $this->loadFiles(
96 __DIR__ . '/Derivation/KDF',
97 __NAMESPACE__ . '\\Derivation\\KDF\\',
98 array($this, 'registerKDF')
99 );
100 }
101
102 protected function loadPBKDF() {
103 $this->loadFiles(
104 __DIR__ . '/Derivation/PBKDF',
105 __NAMESPACE__ . '\\Derivation\\PBKDF\\',
106 array($this, 'registerPBKDF')
107 );
108 }
109
110 }