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


PHP Str::randomBytes方法代码示例

本文整理汇总了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);
 }
开发者ID:ssomenzi,项目名称:silence,代码行数:19,代码来源:ExceptionIdentifier.php

示例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')));
 }
开发者ID:ProgrammingPeter,项目名称:nba-schedule-api,代码行数:19,代码来源:Encrypter.php

示例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')));
 }
开发者ID:jordeytje,项目名称:vlamteddybeer,代码行数:10,代码来源:compiled.php

示例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);
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:14,代码来源:BaseEncrypter.php

示例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));
 }
开发者ID:mikaelmattsson,项目名称:StyleCI,代码行数:12,代码来源:EnableRepoCommandHandler.php


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