예제 #1
0
 /**
  * Derive a key from the supplied arguments
  *
  * @param string $password   The password to derive from
  * @param string $salt       The salt string to use
  * @param int    $iterations The number of iterations to use
  * @param int    $length     The size of the string to generate
  *
  * @return string The derived key
  */
 public function derive($password, $salt, $iterations, $length)
 {
     $size = Hash::getHashSize($this->hash);
     $len = ceil($length / $size);
     $result = '';
     for ($i = 1; $i <= $len; $i++) {
         $tmp = hash_hmac($this->hash, $salt . pack('N', $i), $password, true);
         $res = $tmp;
         for ($j = 1; $j < $iterations; $j++) {
             $tmp = hash_hmac($this->hash, $tmp, $password, true);
             $res ^= $tmp;
         }
         $result .= $res;
     }
     return substr($result, 0, $length);
 }
예제 #2
0
 public function testIsSecureDefault()
 {
     $this->assertEquals(false, Hash::isSecure('foobarbaz'));
 }