29 lines
550 B
PHP
29 lines
550 B
PHP
|
<?php
|
||
|
|
||
|
namespace kernel\services;
|
||
|
|
||
|
use Firebase\JWT\JWT;
|
||
|
use Random\RandomException;
|
||
|
|
||
|
class TokenService
|
||
|
{
|
||
|
|
||
|
public static function JWT(string|\OpenSSLCertificate|\OpenSSLAsymmetricKey $key, string $alg, array $payload = []): string
|
||
|
{
|
||
|
return JWT::encode(
|
||
|
payload: $payload,
|
||
|
key: $key,
|
||
|
alg: $alg
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @throws RandomException
|
||
|
*/
|
||
|
public static function random_bytes(int $ln): string
|
||
|
{
|
||
|
$token = random_bytes($ln);
|
||
|
return bin2hex($token);
|
||
|
}
|
||
|
|
||
|
}
|