當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。