Install constant_time_encoding via Composer
masterTo add this library to your PHP project, use Composer to require the package. This will handle dependencies and autoloading.
composer require paragonie/constant_time_encodingrepository·master·Indexed 21 days ago
https://github.com/paragonie/constant_time_encodingA PHP library providing constant-time character encoding functions for Base64, Base32, and Hex to mitigate cache-timing attacks and prevent information leakage via processor cache misses.
To add this library to your PHP project, use Composer to require the package. This will handle dependencies and autoloading.
composer require paragonie/constant_time_encodingThe ParagonIE\ConstantTime\Encoding class provides a unified static interface for various constant-time encoding formats, including Base64, Base32, and Hex (Base16). This is useful when you want access to all encoding types through a single class.
use ParagonIE\ConstantTime\Encoding;
$data = random_bytes(32);
// Base64
echo Encoding::base64Encode($data), "\n";
// Base32 (lowercase)
echo Encoding::base32Encode($data), "\n";
// Base32 (uppercase)
echo Encoding::base32EncodeUpper($data), "\n";
// Hex (lowercase)
echo Encoding::hexEncode($data), "\n";
// Hex (uppercase)
echo Encoding::hexEncodeUpper($data), "\n";If you only need a specific encoding format, you can use the dedicated classes directly to reduce overhead or simplify your imports. The available specialized classes include Base64 and Base32.
use ParagonIE\ConstantTime\Base64;
use ParagonIE\ConstantTime\Base32;
$data = random_bytes(32);
echo Base64::encode($data), "\n";
echo Base32::encode($data), "\n";The required PHP version depends on which major version of the library you are using:
If your project must support a wide range of PHP versions (e.g., PHP 5 through 8.4), you should set your composer requirement to ^1|^2|^3.