当前位置: 首页>>代码示例>>PHP>>正文


PHP Key::generate方法代码示例

本文整理汇总了PHP中Key::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP Key::generate方法的具体用法?PHP Key::generate怎么用?PHP Key::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Key的用法示例。


在下文中一共展示了Key::generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMultiChangePassword

 public function testMultiChangePassword()
 {
     $firstPassword = 'hello world';
     $secondPassword = 'goodbye sun';
     $otpKey = 'I am a test key';
     $data = openssl_random_pseudo_bytes(117);
     // Set up a user
     $user = new User();
     $user->setOtpKey($otpKey, $firstPassword);
     // Setup a key
     $defaultKeyPassphrase = $user->dangerouslyRegenerateAccountKeyPassphrase($firstPassword);
     $key = Key::generate($defaultKeyPassphrase, 1024);
     $user->accountKey = $key;
     // Encrypt some data
     $encryptedData = $user->getAccountKey()->encrypt($data);
     // Change user's password
     // This must update the password on the default key and OTP key as well
     $user->changePassword($firstPassword, $secondPassword);
     // Decrypt data
     $newKeyPassphrase = $user->getAccountKeyPassphrase($secondPassword);
     $decrypted = $user->getAccountKey()->decrypt($encryptedData, $newKeyPassphrase);
     // Default Key passphrase should have changed and remain valid
     $this->assertNotEquals($newKeyPassphrase, $defaultKeyPassphrase);
     $this->assertEquals($data, $decrypted);
     // OTP key should have been encrypted with the new password
     $this->assertEquals($otpKey, $user->getOtpKey($secondPassword));
 }
开发者ID:stecman,项目名称:passnote,代码行数:27,代码来源:UserTest.php

示例2: createWithKeys

 /**
  * Create a user and set up keys
  *
  * The steps to create a user per the spec of the system are quite specific.
  * This method should be used when creating a user to avoid duplication of
  * the steps needed to set up a completely new user correctly.
  *
  * NOTE: the key is not added to User->keys as these need to be saved separately.
  *
  * @param string $email
  * @param string $password
  * @return User
  */
 public static function createWithKeys($email, $password)
 {
     $user = new User();
     $user->email = $email;
     $keyPassphrase = $user->dangerouslyRegenerateAccountKeyPassphrase($password);
     $key = Key::generate($keyPassphrase);
     $user->accountKey = $key;
     return $user;
 }
开发者ID:stecman,项目名称:passnote,代码行数:22,代码来源:User.php

示例3: setUp

 protected function setUp()
 {
     $this->object = new Object();
     $this->object->key = Key::generate(self::KEY_PASSPHRASE, 386);
 }
开发者ID:stecman,项目名称:passnote,代码行数:5,代码来源:ObjectTest.php

示例4: testExceedMaxMessageLength

 /**
  * @expectedException \Stecman\Passnote\MessageSizeException
  */
 public function testExceedMaxMessageLength()
 {
     $key = Key::generate('smith', 386);
     $key->encrypt(openssl_random_pseudo_bytes($key->getMaxMessageSize() + 1));
 }
开发者ID:stecman,项目名称:passnote,代码行数:8,代码来源:KeyTest.php

示例5: createAction

 /**
  * Create a new user
  *
  * @param $email
  */
 public function createAction($email)
 {
     if (!$this->isValidEmail($email)) {
         die("'{$email}' is not a valid email address\n");
     }
     if ($user = User::findFirst(['email = :email:', 'bind' => ['email' => $email]])) {
         die("The account {$email} already exists. Duplicate account emails are not allowed.\n");
     }
     echo "Creating user '{$email}'\n";
     $password = $this->promptCreatePassword();
     echo "Keying...\n";
     $user = new User();
     $user->email = $email;
     $user->setPassword($password);
     // Create OTP key
     $otp = Seed::generate(40);
     $user->setOtpKey($otp->getValue(Seed::FORMAT_BASE32), $password);
     // Create account key
     $key = Key::generate($user->dangerouslyRegenerateAccountKeyPassphrase($password));
     $key->setName('Account key');
     // Save user and key
     $this->db->begin();
     $user->create();
     $key->user_id = $user->id;
     $key->create();
     $user->accountKey_id = $key->id;
     $user->update();
     $this->db->commit();
     echo "Created user {$email} with id {$user->id}\n";
     echo "OTP: {$this->generateOtpUri($user, $otp)}\n";
 }
开发者ID:stecman,项目名称:passnote,代码行数:36,代码来源:UsersTask.php


注:本文中的Key::generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。