本文整理匯總了PHP中Illuminate\Support\Str::randomBytes方法的典型用法代碼示例。如果您正苦於以下問題:PHP Str::randomBytes方法的具體用法?PHP Str::randomBytes怎麽用?PHP Str::randomBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::randomBytes方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generate
/**
* Generate a new uuid.
*
* We're generating uuids according to the official v4 spec.
*
* @return string
*/
protected function generate()
{
$hash = bin2hex(Str::randomBytes(16));
$timeHi = hexdec(substr($hash, 12, 4)) & 0xfff;
$timeHi &= ~0xf000;
$timeHi |= 4 << 12;
$clockSeqHi = hexdec(substr($hash, 16, 2)) & 0x3f;
$clockSeqHi &= ~0xc0;
$clockSeqHi |= 0x80;
$params = [substr($hash, 0, 8), substr($hash, 8, 4), sprintf('%04x', $timeHi), sprintf('%02x', $clockSeqHi), substr($hash, 18, 2), substr($hash, 20, 12)];
return vsprintf('%08s-%04s-%04s-%02s%02s-%012s', $params);
}
示例2: encrypt
/**
* Encrypt the given value.
*
* @param string $value
* @return string
*/
public function encrypt($value)
{
$iv = Str::randomBytes($this->getIvSize());
$value = openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);
if ($value === false) {
throw new EncryptException('Could not encrypt the data.');
}
// Once we have the encrypted value we will go ahead base64_encode the input
// vector and create the MAC for the encrypted value so we can verify its
// authenticity. Then, we'll JSON encode the data in a "payload" array.
$mac = $this->hash($iv = base64_encode($iv), $value);
return base64_encode(json_encode(compact('iv', 'value', 'mac')));
}
示例3: encrypt
public function encrypt($value)
{
$iv = Str::randomBytes($this->getIvSize());
$value = openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);
if ($value === false) {
throw new EncryptException('Could not encrypt the data.');
}
$mac = $this->hash($iv = base64_encode($iv), $value);
return base64_encode(json_encode(compact('iv', 'value', 'mac')));
}
示例4: validMac
/**
* Determine if the MAC for the given payload is valid.
*
* @param array $payload
* @return bool
*
* @throws \RuntimeException
*/
protected function validMac(array $payload)
{
$bytes = Str::randomBytes(16);
$calcMac = hash_hmac('sha256', $this->hash($payload['iv'], $payload['value']), $bytes, true);
return Str::equals(hash_hmac('sha256', $payload['mac'], $bytes, true), $calcMac);
}
示例5: handle
/**
* Handle the enable repo command.
*
* @param \StyleCI\StyleCI\Commands\Repo\EnableRepoCommand $command
*
* @return void
*/
public function handle(EnableRepoCommand $command)
{
$repo = Repo::create(['id' => $command->id, 'user_id' => $command->user->id, 'name' => $command->name, 'default_branch' => $command->branch, 'token' => bin2hex(Str::randomBytes(10))]);
event(new RepoWasEnabledEvent($repo));
}