constant_time_encoding

repository·master·Indexed 21 days ago

https://github.com/paragonie/constant_time_encoding

A 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.

Tokens
545
Snippets
3
Records
4
Agent score
25%

What's inside constant_time_encoding

  1. Use the Encoding class for multiple encoding formats

    master

    The 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";
  2. Use specific encoding classes for individual formats

    master

    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";
  3. PHP version requirements

    master

    The required PHP version depends on which major version of the library you are using:

    • Version 3: Requires PHP 8 or newer.
    • Version 2: Requires PHP 7 or newer.
    • Version 1: Supports PHP 5.

    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.