Example #1
0
 /**
  * Build a new instance
  *
  * @param Generator $generator  The random generator to use for seeds
  * @param Factory   $factory    The hash factory to use for this instance
  *
  * @return void
  */
 public function __construct(\CryptLib\Random\Generator $generator = null)
 {
     if (is_null($generator)) {
         $random = new RandomFactory();
         $generator = $random->getMediumStrengthGenerator();
     }
     $this->generator = $generator;
 }
Example #2
0
 /**
  * Build a new instance
  *
  * @param int       $iterations The number of times to iterate the hash
  * @param Generator $generator  The random generator to use for seeds
  *
  * @return void
  */
 public function __construct($iterations = 8, \CryptLib\Random\Generator $generator = null)
 {
     if ($iterations > 31 || $iterations < 4) {
         throw new \InvalidArgumentException('Invalid Iteration Count Supplied');
     }
     $this->iterations = $iterations;
     if (is_null($generator)) {
         $random = new RandomFactory();
         $generator = $random->getMediumStrengthGenerator();
     }
     $this->generator = $generator;
 }
Example #3
0
 /**
  * Build a new instance of the PBKDF password class
  *
  * @param PBKDF     $derivation The derivation class to use
  * @param int       $size       The size of hash to generate
  * @param int       $iterations The number of iterations to perform
  * @param Generator $generator  The Random Generator to use
  *
  * @return void;
  */
 public function __construct(\CryptLib\Key\Derivation\PBKDF $derivation = null, $size = 40, $iterations = 5000, \CryptLib\Random\Generator $generator = null)
 {
     if (is_null($derivation)) {
         $derivation = new PBKDF2();
     }
     $this->derivation = $derivation;
     $this->size = $size < 40 ? 40 : (int) $size;
     $this->iterations = $iterations > 0 ? (int) $iterations : 1;
     if (is_null($generator)) {
         $factory = new RandomFactory();
         $generator = $factory->getMediumStrengthGenerator();
     }
     $this->generator = $generator;
 }
Example #4
0
 /**
  * @covers CryptLib\Random\Factory::getMediumStrengthGenerator
  * @covers CryptLib\Random\Factory::getGenerator
  * @covers CryptLib\Random\Factory::findMixer
  */
 public function testGetMediumStrengthGenerator()
 {
     $factory = new Factory();
     $generator = $factory->getMediumStrengthGenerator();
     $this->assertTrue($generator instanceof CryptLib\Random\Generator);
     $mixer = call_user_func(array(get_class($generator->getMixer()), 'getStrength'));
     $this->assertTrue($mixer->compare(new Strength(Strength::MEDIUM)) <= 0);
     foreach ($generator->getSources() as $source) {
         $strength = call_user_func(array(get_class($source), 'getStrength'));
         $this->assertTrue($strength->compare(new Strength(Strength::MEDIUM)) >= 0);
     }
 }
Example #5
0
 /**
  * Shuffle a string and return the randomized string
  *
  * @param string $string The string to randomize
  *
  * @return string The shuffled string
  */
 public function shuffleString($string)
 {
     $factory = new RandomFactory();
     $generator = $factory->getMediumStrengthGenerator();
     $array = str_split($string);
     $result = $this->shuffleArray($array);
     return implode('', $result);
 }