本文整理汇总了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));
}
示例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;
}
示例3: setUp
protected function setUp()
{
$this->object = new Object();
$this->object->key = Key::generate(self::KEY_PASSPHRASE, 386);
}
示例4: testExceedMaxMessageLength
/**
* @expectedException \Stecman\Passnote\MessageSizeException
*/
public function testExceedMaxMessageLength()
{
$key = Key::generate('smith', 386);
$key->encrypt(openssl_random_pseudo_bytes($key->getMaxMessageSize() + 1));
}
示例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";
}