本文整理汇总了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));
}