php签名

qmister -
php签名
安装
composer require whereof/signature
支持加密方式alg实现方式key参数ES384openssl数组包含publicKey和privateKeyES256openssl数组包含publicKey和privateKeyHS256hash_hmac字符串HS384hash_hmac字符串HS512hash_hmac字符串RS256openssl数组包含publicKey和privateKeyRS384openssl数组包含publicKey和privateKeyRS512openssl数组包含publicKey和privateKeyEdDSAsodium_crypto字符串异常捕捉
whereof\Signature\Exceptions\SignatureInvalidException 签名不正确
whereof\Signature\Exceptions\BeforeValidException 签名在某个时间点之后才能用
whereof\Signature\Exceptions\ExpiredException 签名失效
Example
$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);
Example with RS256 (openssl)
$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);
Example with EdDSA (libsodium and Ed25519 signature)
$jwt = new \whereof\Signature\Jwt( \whereof\Signature\Support\KeyHelper::EdDSA(),'EdDSA'));
$token = $jwt->encode($payload);
$data = $jwt->decode($token);
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

php介绍

PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。
上一篇: Workerman的使用

Tags 标签

php

扩展阅读

加个好友,技术交流

1628738909466805.jpg