7 * @category PHPCryptLib
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@@
15 namespace CryptLib\Key
;
18 * The core Key Factory
20 * @category PHPCryptLib
22 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
24 class Factory
extends \CryptLib\Core\AbstractFactory
{
27 * @var array An array of KDF class implementations
29 protected $kdf = array();
32 * @var array An array of PBKDF class implementations
34 protected $pbkdf = array();
37 * @var array An array of symmetric key generator implementations
39 protected $symmetricGenerators = array();
42 * Construct the instance, loading the core implementations
46 public function __construct() {
49 //$this->loadSymmetricGenerators();
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);
57 throw new \
InvalidArgumentException('Unsupported KDF');
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);
65 throw new \
InvalidArgumentException('Unsupported PBKDF');
68 public function getPBKDFFromSignature($signature) {
69 list ($name, $hash) = explode('-', $signature, 2);
70 return $this->getPBKDF($name, array('hash' => $hash));
73 public function getSymmetricKeyGenerator() {
76 public function registerKDF($name, $class) {
79 __NAMESPACE__
. '\\Derivation\\KDF',
85 public function registerPBKDF($name, $class) {
88 __NAMESPACE__
. '\\Derivation\\PBKDF',
94 protected function loadKDF() {
96 __DIR__
. '/Derivation/KDF',
97 __NAMESPACE__
. '\\Derivation\\KDF\\',
98 array($this, 'registerKDF')
102 protected function loadPBKDF() {
104 __DIR__
. '/Derivation/PBKDF',
105 __NAMESPACE__
. '\\Derivation\\PBKDF\\',
106 array($this, 'registerPBKDF')