-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77be68d
commit d819bfe
Showing
5 changed files
with
29 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
<?php | ||
/** | ||
* @CreateTime: 2020/11/18 10:16 下午 | ||
* @Author: huizhang <[email protected]> | ||
* @Copyright: copyright(2020) Easyswoole all rights reserved | ||
* @Description: 签名生成 | ||
*/ | ||
|
||
namespace EasySwoole\Jwt; | ||
|
||
use EasySwoole\Spl\SplBean; | ||
|
||
class Signature extends SplBean | ||
class Signature extends \stdClass | ||
{ | ||
|
||
protected $secretKey; | ||
protected $header; | ||
protected $payload; | ||
protected $alg; | ||
|
||
/** | ||
* php 7.4以下不支持在__toString()抛出异常 | ||
*/ | ||
public function __toString() | ||
{ | ||
$content = $this->header . '.' . $this->payload; | ||
|
@@ -29,12 +19,12 @@ public function __toString() | |
switch ($this->alg) { | ||
case Jwt::ALG_METHOD_HMACSHA256: | ||
case Jwt::ALG_METHOD_HS256: | ||
$signature = Encryption::getInstance()->base64UrlEncode( | ||
$signature = Encryption::base64UrlEncode( | ||
hash_hmac('sha256', $content, $this->secretKey, true) | ||
); | ||
break; | ||
case Jwt::ALG_METHOD_AES: | ||
$signature = Encryption::getInstance()->base64UrlEncode( | ||
$signature = Encryption::base64UrlEncode( | ||
openssl_encrypt($content, 'AES-128-ECB', $this->secretKey) | ||
); | ||
break; | ||
|
@@ -43,7 +33,7 @@ public function __toString() | |
if (!$success) { | ||
$signature = ""; | ||
} else { | ||
$signature = Encryption::getInstance()->base64UrlEncode($signature); | ||
$signature = Encryption::base64UrlEncode($signature); | ||
} | ||
break; | ||
default: | ||
|
@@ -52,4 +42,11 @@ public function __toString() | |
return $signature; | ||
} | ||
|
||
function __construct(array $data) | ||
{ | ||
foreach ($data as $key => $item){ | ||
$this->{$key} = $item; | ||
} | ||
} | ||
|
||
} |