Add session flags management and encryption key support
This commit is contained in:
parent
790262db08
commit
1d452bc71b
8 changed files with 209 additions and 76 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace Socialbox\Classes;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Random\RandomException;
|
||||
use Socialbox\Exceptions\CryptographyException;
|
||||
use Socialbox\Objects\KeyPair;
|
||||
|
||||
|
@ -266,4 +267,24 @@ class Cryptography
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random sequence of bytes with a length determined between the specified minimum and maximum.
|
||||
*
|
||||
* @param int $minLength The minimum length of the generated byte sequence.
|
||||
* @param int $maxLength The maximum length of the generated byte sequence.
|
||||
* @return string A hexadecimal string representing the random byte sequence.
|
||||
* @throws CryptographyException If the random byte generation fails.
|
||||
*/
|
||||
public static function randomBytes(int $minLength, int $maxLength): string
|
||||
{
|
||||
try
|
||||
{
|
||||
return bin2hex(random_bytes(random_int($minLength, $maxLength)));
|
||||
}
|
||||
catch(RandomException $e)
|
||||
{
|
||||
throw new CryptographyException('Failed to generate random bytes: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue