3 * To change this template, choose Tools | Templates
4 * and open the template in the editor.
5 * @version Build @@version@@
8 namespace CryptLib\Key\Symmetric\Generator
;
10 use CryptLib\Random\Factory
as RandomFactory
;
11 use CryptLib\Key\Factory
as KeyFactory
;
12 use CryptLib\Key\Symmetric\Raw
as Raw
;
15 * Description of mtrand
19 class Internal
implements \CryptLib\Key\Generator
{
21 protected $kdf = null;
23 protected $random = null;
25 public static function test() {
29 public function __construct(array $options = array()) {
30 $options +
= array('kdf' => null, 'random' => null);
31 if (is_null($options['kdf'])) {
32 $factory = new KeyFactory();
33 $options['kdf'] = $factory->getKdf('kdf3');
35 $this->kdf
= $options['kdf'];
36 if (is_null($options['random'])) {
37 $options['random'] = new RandomFactory();
39 $this->random
= $options['random'];
42 public function __toString() {
45 public function generate(
46 \CryptLib\Core\Strength
$strength,
50 $generator = $this->random
->getGenerator($strength);
51 $seed = $generator->generate($size);
52 $key = $this->kdf
->derive($seed, $size, $passphrase);
53 return new Raw(substr($key, 0, $size));
56 public function getType() {
57 return static::TYPE_SYMMETRIC
;