예제 #1
0
 /**
  * Returns a new set of keys for message encryption and signing.
  *
  * @param string $seed The seed to use to create repeatable keys.
  * @param string $hashKey The key to hash the key with.
  * @return array
  */
 public static function generateKeys($seed = null, $hashKey = '')
 {
     # The keys are being generated from a seed.
     if ($seed !== null) {
         # Generate some repeatable hashes to create keys against for recovery
         $encrHash = Hash::hash($seed, $hashKey, Constants::BOX_SEEDBYTES);
         $signHash = Hash::hash($seed, $hashKey, Constants::SIGN_SEEDBYTES);
         # Build recoverable pre-seeded key pairs.
         $seeds = ['encr' => \Sodium\crypto_box_keypair($encrHash), 'sign' => \Sodium\crypto_sign_keypair($signHash)];
     } else {
         # Build un-recoverable key pairs.
         $seeds = ['encr' => \Sodium\crypto_box_keypair(), 'sign' => \Sodium\crypto_sign_keypair()];
     }
     # Return the two generated key pairs to the client.
     return ['encr' => ['pri' => Helpers::bin2hex(\Sodium\crypto_box_secretkey($seeds['encr'])), 'pub' => Helpers::bin2hex(\Sodium\crypto_box_publickey($seeds['encr']))], 'sign' => ['pri' => Helpers::bin2hex(\Sodium\crypto_sign_secretkey($seeds['sign'])), 'pub' => Helpers::bin2hex(\Sodium\crypto_sign_publickey($seeds['sign']))]];
 }
예제 #2
0
 /**
  * @depends passwordTest
  * @expectedException SimpleAPISecurity\PHP\Exceptions\InvalidTypeException
  * @expectedExceptionMessage Expected string parameter for passwordHash in verifyPassword
  */
 public function passwordTestBashPasswordHash()
 {
     $password = '******';
     Hash::verifyPassword($password, 1);
 }
 /**
  * Check the given plain value against a hash.
  *
  * @param string $value
  * @param string $hashedValue
  * @param array  $unusedOptions Options are not used for Sodium password verification
  *
  * @return bool
  */
 public function check($value, $hashedValue, array $unusedOptions = [])
 {
     return Hash::verifyPassword($value, $hashedValue);
 }