Exemple #1
0
 /**
  * Derive an encryption key from a password and a salt
  * 
  * @param string $password
  * @param string $salt
  * @param int $type
  * @return array|\ParagonIE\Halite\Key
  * @throws CryptoException\InvalidFlags
  */
 public static function deriveFromPassword($password, $salt, $type = self::CRYPTO_BOX)
 {
     if ($type & self::ASYMMETRIC === 0) {
         $type &= self::ASYMMETRIC;
     }
     return parent::deriveFromPassword($password, $salt, $type);
 }
Exemple #2
0
 /**
  * Derive an encryption key from a password and a salt
  * 
  * @param string $password
  * @param string $salt
  * @param int $type
  * @return array|\ParagonIE\Halite\Key
  * @throws CryptoException\InvalidFlags
  */
 public static function deriveFromPassword($password, $salt, $type = self::CRYPTO_SECRETBOX)
 {
     if ($type & self::ASYMMETRIC !== 0) {
         $type ^= self::ASYMMETRIC;
     }
     if ($type & self::PUBLIC_KEY !== 0) {
         $type ^= self::PUBLIC_KEY;
     }
     return parent::deriveFromPassword($password, $salt, $type);
 }
Exemple #3
0
 public function testDerive()
 {
     $key = Key::deriveFromPassword('apple', "\t\n\v\f\r" . "");
     $this->assertEquals($key->get(), "6¦Â¹je\r€¿~^XóÖ" . "63•uÞû7¥B½TX-");
 }
Exemple #4
0
 public function testDerive()
 {
     $key = Key::deriveFromPassword('apple', "\t\n\v\f\r" . "");
     $this->assertEquals($key->get(), "6�¹je\r��~^X��" . "63�u��7�B�TX-");
 }
Exemple #5
0
 /**
  * Derive an encryption key from a password and a salt
  * 
  * @param string $password
  * @param string $salt
  * @param int $type
  * @return array|\ParagonIE\Halite\Key
  * @throws CryptoAlert\InvalidFlags
  */
 public static function deriveFromPassword($password, $salt, $type = self::CRYPTO_BOX)
 {
     if (($type & Key::ASYMMETRIC) === 0) {
         throw new CryptoAlert\InvalidKey('An asymmetric key type must be passed to KeyPair::generate()');
     }
     if (($type & Key::ENCRYPTION) !== 0) {
         return Key::deriveFromPassword($password, $salt, Key::CRYPTO_BOX);
     } elseif (($type & Key::SIGNATURE) !== 0) {
         return Key::deriveFromPassword($password, $salt, Key::CRYPTO_SIGN);
     }
     throw new CryptoAlert\InvalidKey('You must specify encryption or authentication flags.');
 }