MicroFrameWork/kernel/services/TokenService.php
2024-10-22 16:40:40 +03:00

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);
}
}