composer require whereof/signature
alg |
实现形式 |
key 参数 |
ES384 |
openssl |
数组蕴含 publicKey 和 privateKey |
ES256 |
openssl |
数组蕴含 publicKey 和 privateKey |
HS256 |
hash_hmac |
字符串 |
HS384 |
hash_hmac |
字符串 |
HS512 |
hash_hmac |
字符串 |
RS256 |
openssl |
数组蕴含 publicKey 和 privateKey |
RS384 |
openssl |
数组蕴含 publicKey 和 privateKey |
RS512 |
openssl |
数组蕴含 publicKey 和 privateKey |
EdDSA |
sodium_crypto |
字符串 |
whereof\Signature\Exceptions\SignatureInvalidException 签名不正确
whereof\Signature\Exceptions\BeforeValidException 签名在某个工夫点之后能力用
whereof\Signature\Exceptions\ExpiredException 签名生效
$time = time();
$payload = [
'iss' => 'github.com',// 签发人
'iat' => $time, // 签发工夫
'nbf' => $time, // 生成签名之后失效
'exp' => $time + 7200, // 过期工夫
'data' => [
'id' => 88,
'username' => 'whereof'
],
];
$jwt = new \whereof\Signature\Jwt(\whereof\Signature\Support\KeyHelper::key());
$token = $jwt->encode($payload);
$data = $jwt->encode($token);
$jwt = new \whereof\Signature\Jwt(\whereof\Signature\Support\KeyHelper::RS256(),'RS256'));
$jwt = new \whereof\Signature\Jwt(\whereof\Signature\Support\KeyHelper::RS256Pem(),'RS256'));
$token = $jwt->encode($payload);
$data = $jwt->decode($token);
$jwt = new \whereof\Signature\Jwt(\whereof\Signature\Support\KeyHelper::EdDSA(),'EdDSA'));
$token = $jwt->encode($payload);
$data = $jwt->decode($token);