new kernel, ms bearer
This commit is contained in:
62
kernel/services/TokenService.php
Normal file
62
kernel/services/TokenService.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\services;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use kernel\helpers\Debug;
|
||||
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
|
||||
{
|
||||
return bin2hex(random_bytes($ln));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public static function md5(): string
|
||||
{
|
||||
return md5(microtime() . self::getSalt() . time());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public static function crypt(): string
|
||||
{
|
||||
return crypt(microtime(), self::getSalt());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public static function hash(string $alg): string
|
||||
{
|
||||
return hash($alg, self::getSalt());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public static function getSalt(): string
|
||||
{
|
||||
return bin2hex(random_bytes(10));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user