PHPackages                             skywalker-labs/constant-time-encoding - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. skywalker-labs/constant-time-encoding

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

skywalker-labs/constant-time-encoding
=====================================

Constant-time implementations of RFC 4648 encoding (Base64, Base32, Hex) and other variants (Base64UrlSafe, Base64DotSlash, Base32Hex)

v1.0.0(4mo ago)111MITPHPPHP ^7.4 || ^8.0 || ^9.0CI passing

Since Feb 15Pushed 4mo agoCompare

[ Source](https://github.com/skywalker-labs/constant-time-encoding)[ Packagist](https://packagist.org/packages/skywalker-labs/constant-time-encoding)[ Docs](https://github.com/skywalker-labs/constant-time-encoding)[ GitHub Sponsors](https://github.com/sponsors/ermradulsharma)[ RSS](/packages/skywalker-labs-constant-time-encoding/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (1)

Skywalker Constant-Time Encoding
================================

[](#skywalker-constant-time-encoding)

[![Build Status](https://github.com/skywalker-labs/constant-time-encoding/actions/workflows/ci.yml/badge.svg)](https://github.com/skywalker-labs/constant-time-encoding/actions)[![Static Analysis](https://github.com/skywalker-labs/constant-time-encoding/actions/workflows/psalm.yml/badge.svg)](https://github.com/skywalker-labs/constant-time-encoding/actions)[![Latest Stable Version](https://camo.githubusercontent.com/a2e77a463b09363fec6d9a449d9b6d986ce29ecde0409f60d49d563d26f207ac/68747470733a2f2f706f7365722e707567782e6f72672f736b7977616c6b65722d6c6162732f636f6e7374616e742d74696d652d656e636f64696e672f762f737461626c65)](https://packagist.org/packages/skywalker-labs/constant-time-encoding)[![Latest Unstable Version](https://camo.githubusercontent.com/35062f4b711cafb1621ddd70b654e72f36bc4ad7409f20b33994fcc321c6e27a/68747470733a2f2f706f7365722e707567782e6f72672f736b7977616c6b65722d6c6162732f636f6e7374616e742d74696d652d656e636f64696e672f762f756e737461626c65)](https://packagist.org/packages/skywalker-labs/constant-time-encoding)[![License](https://camo.githubusercontent.com/08ca50265a185eab83e92ace4db64f76096751cd41b85c0b6e95a79de4dcb69c/68747470733a2f2f706f7365722e707567782e6f72672f736b7977616c6b65722d6c6162732f636f6e7374616e742d74696d652d656e636f64696e672f6c6963656e7365)](https://packagist.org/packages/skywalker-labs/constant-time-encoding)[![Downloads](https://camo.githubusercontent.com/e5b1aa13dc3bebc1b9bb760f2ac98e558b04507ec8a6ee166025af5bdc070ec9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736b7977616c6b65722d6c6162732f636f6e7374616e742d74696d652d656e636f64696e672e737667)](https://packagist.org/packages/skywalker-labs/constant-time-encoding)

Constant-time implementations of RFC 4648 encoding (Base64, Base32, Hex) and other variants.

This library aims to offer character encoding functions that do not leak information about what you are encoding/decoding via processor cache misses.

Features
--------

[](#features)

- **Constant-Time Encoding/Decoding**: Prevents cache-timing attacks.
- **Multiple Encodings**:
    - **Base64** (RFC 4648)
    - **Base64UrlSafe** (URL-safe variant)
    - **Base64DotSlash** (Crypt version, `./[A-Z][a-z][0-9]`)
    - **Base64DotSlashOrdered** (Ordered variant, `[.-9][A-Z][a-z]`)
    - **Base32** (RFC 4648)
    - **Base32Hex** (RFC 4648 base32hex)
    - **Hex** (Base16)
- **Security**: Uses `pack()` and `unpack()` instead of `chr()` and `ord()` for safer bit manipulation.
- **Robust**: Strict padding validation (optional).

Requirements
------------

[](#requirements)

- PHP 7.4 or newer (including PHP 8.x).

Installation
------------

[](#installation)

```
composer require skywalker-labs/constant-time-encoding
```

Usage
-----

[](#usage)

You can use the `Skywalker\ConstantTime\Encoding` class as a facade for all encoding methods, or use specific classes directly.

### Using the Encoding Facade

[](#using-the-encoding-facade)

```
use Skywalker\ConstantTime\Encoding;

// Sample data
$data = random_bytes(32);

// Base64
echo Encoding::base64Encode($data), "\n";

// Base32 (Uppercase)
echo Encoding::base32EncodeUpper($data), "\n";

// Base32 (Standard)
echo Encoding::base32Encode($data), "\n";

// Hex (Base16)
echo Encoding::hexEncode($data), "\n";
echo Encoding::hexEncodeUpper($data), "\n";
```

### Using Specific Classes

[](#using-specific-classes)

If you only need a specific encoding, you can import the relevant class directly:

```
use Skywalker\ConstantTime\Base64;
use Skywalker\ConstantTime\Base32;
use Skywalker\ConstantTime\Hex;

$data = random_bytes(32);

// Encode
$b64 = Base64::encode($data);
$b32 = Base32::encode($data);
$hex = Hex::encode($data);

// Decode
$raw = Base64::decode($b64);
```

### Output Example

[](#output-example)

```
1VilPkeVqirlPifk5scbzcTTbMT2clp+Zkyv9VFFasE=
2VMKKPSHSWVCVZJ6E7SONRY3ZXCNG3GE6ZZFU7TGJSX7KUKFNLAQ====
2vmkkpshswvcvzj6e7sonry3zxcng3ge6zzfu7tgjsx7kukfnlaq====
d558a53e4795aa2ae53e27e4e6c71bcdc4d36cc4f6725a7e664caff551456ac1
D558A53E4795AA2AE53E27E4E6C71BDCC4D36CC4F6725A7E664CAFF551456AC1

```

Security
--------

[](#security)

This library was designed to eliminate cache-timing side-channels from encoding operations. It is intended for use in cryptographic contexts where timing leaks could expose sensitive data.

Support
-------

[](#support)

If your company uses this library in their products or services, you may be interested in [purchasing a support contract from Skywalker Labs](https://skywalker-labs.com/).

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance76

Regular maintenance activity

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

138d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/68241409c48fd5184c979320937b363826a5a9aeeb4260e8d1fa753be39458b9?d=identicon)[ermradulsharma](/maintainers/ermradulsharma)

---

Top Contributors

[![ermradulsharma](https://avatars.githubusercontent.com/u/15956546?v=4)](https://github.com/ermradulsharma "ermradulsharma (3 commits)")

---

Tags

encodingbase64rfc4648base32hexbase16bin2hexhex2binbase64\_encodebase64\_decodebase32\_encodebase32\_decode

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/skywalker-labs-constant-time-encoding/health.svg)

```
[![Health](https://phpackages.com/badges/skywalker-labs-constant-time-encoding/health.svg)](https://phpackages.com/packages/skywalker-labs-constant-time-encoding)
```

###  Alternatives

[paragonie/constant_time_encoding

Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)

908363.2M190](/packages/paragonie-constant-time-encoding)[spomky-labs/base64url

Base 64 URL Safe Encoding/Decoding PHP Library

15442.9M61](/packages/spomky-labs-base64url)[christian-riesen/base32

Base32 encoder/decoder according to RFC 4648

13333.9M74](/packages/christian-riesen-base32)[xobotyi/basen

Text and integers encoding utilities for PHP with no extensions dependencies. Base32, Base58, Base64 and much more!

1220.4k](/packages/xobotyi-basen)[paquettg/string-encode

Facilitating the process of altering string encoding in PHP.

699.1M43](/packages/paquettg-string-encode)[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.9M23](/packages/ozdemirburak-iris)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
