br-crypto
Installation
SKILL.md
Better Route crypto helpers
Use the library helpers instead of reimplementing small security primitives.
use BetterRoute\Support\Crypto;
use BetterRoute\Support\CryptoEncoding;
$state = Crypto::token(32); // Base64URL by default.
$nonce = Crypto::token(32, CryptoEncoding::Base64Url);
$hex = Crypto::tokenHex(32);
$encoded = Crypto::base64UrlEncode($raw);
$decoded = Crypto::base64UrlDecode($encoded);
if (!Crypto::equals($expected, $provided)) {
throw new \BetterRoute\Http\ApiException('Invalid token.', 401, 'invalid_token');
}