PHPackages                             paragonie/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. paragonie/constant\_time\_encoding

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

paragonie/constant\_time\_encoding
==================================

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

v3.1.3(7mo ago)903329.7M—3.2%35[1 PRs](https://github.com/paragonie/constant_time_encoding/pulls)20MITPHPPHP ^8CI failing

Since Feb 3Pushed 7mo ago12 watchersCompare

[ Source](https://github.com/paragonie/constant_time_encoding)[ Packagist](https://packagist.org/packages/paragonie/constant_time_encoding)[ RSS](/packages/paragonie-constant-time-encoding/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (44)Used By (20)

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

[](#constant-time-encoding)

[![Build Status](https://github.com/paragonie/constant_time_encoding/actions/workflows/ci.yml/badge.svg)](https://github.com/paragonie/constant_time_encoding/actions)[![Static Analysis](https://github.com/paragonie/constant_time_encoding/actions/workflows/psalm.yml/badge.svg)](https://github.com/paragonie/constant_time_encoding/actions)[![Latest Stable Version](https://camo.githubusercontent.com/7975edd2d3a93074bc169da4f3b13c29f2fb4d2a10ccf325f3f4fee0a0c62085/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f636f6e7374616e745f74696d655f656e636f64696e672f762f737461626c65)](https://packagist.org/packages/paragonie/constant_time_encoding)[![Latest Unstable Version](https://camo.githubusercontent.com/02a3bb29402a0683c25fe889195b06d5dd1ac5c6dee13161ea16fb31698ed842/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f636f6e7374616e745f74696d655f656e636f64696e672f762f756e737461626c65)](https://packagist.org/packages/paragonie/constant_time_encoding)[![License](https://camo.githubusercontent.com/b066d92ffa91719f7c794fe5113f4772a338584d477e5462a31e32c634066b9b/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f636f6e7374616e745f74696d655f656e636f64696e672f6c6963656e7365)](https://packagist.org/packages/paragonie/constant_time_encoding)[![Downloads](https://camo.githubusercontent.com/8a1fa506d31940949dbced9e6e1516928e2ad6d3f9f1625d0943ee1f8ef415ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70617261676f6e69652f636f6e7374616e745f74696d655f656e636f64696e672e737667)](https://packagist.org/packages/paragonie/constant_time_encoding)

Based on the [constant-time base64 implementation made by Steve "Sc00bz" Thomas](https://github.com/Sc00bz/ConstTimeEncoding), this library aims to offer character encoding functions that do not leak information about what you are encoding/decoding via processor cache misses. Further reading on [cache-timing attacks](http://blog.ircmaxell.com/2014/11/its-all-about-time.html).

Our fork offers the following enhancements:

- `mbstring.func_overload` resistance
- Unit tests
- Composer- and Packagist-ready
- Base16 encoding
- Base32 encoding
- Uses `pack()` and `unpack()` instead of `chr()` and `ord()`

PHP Version Requirements
------------------------

[](#php-version-requirements)

Version 3 of this library should work on **PHP 8** or newer.

Version 2 of this library should work on **PHP 7** or newer. See [the v2.x branch](https://github.com/paragonie/constant_time_encoding/tree/v2.x).

For PHP 5 support, see [the v1.x branch](https://github.com/paragonie/constant_time_encoding/tree/v1.x).

If you are adding this as a dependency to a project intended to work on PHP 5 through 8.4, please set the required version to `^1|^2|^3`.

How to Install
--------------

[](#how-to-install)

```
composer require paragonie/constant_time_encoding
```

How to Use
----------

[](#how-to-use)

```
use ParagonIE\ConstantTime\Encoding;

// possibly (if applicable):
// require 'vendor/autoload.php';

$data = random_bytes(32);
echo Encoding::base64Encode($data), "\n";
echo Encoding::base32EncodeUpper($data), "\n";
echo Encoding::base32Encode($data), "\n";
echo Encoding::hexEncode($data), "\n";
echo Encoding::hexEncodeUpper($data), "\n";
```

Example output:

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

```

If you only need a particular variant, you can just reference the required class like so:

```
use ParagonIE\ConstantTime\Base64;
use ParagonIE\ConstantTime\Base32;

$data = random_bytes(32);
echo Base64::encode($data), "\n";
echo Base32::encode($data), "\n";
```

Example output:

```
1VilPkeVqirlPifk5scbzcTTbMT2clp+Zkyv9VFFasE=
2vmkkpshswvcvzj6e7sonry3zxcng3ge6zzfu7tgjsx7kukfnlaq====

```

Support Contracts
-----------------

[](#support-contracts)

If your company uses this library in their products or services, you may be interested in [purchasing a support contract from Paragon Initiative Enterprises](https://paragonie.com/enterprise).

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance62

Regular maintenance activity

Popularity78

Solid adoption and visibility

Community44

Growing community involvement

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 64.4% 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

Every ~88 days

Recently: every ~0 days

Total

41

Last Release

237d ago

Major Versions

v1.0.4 → v2.2.32019-01-03

v1.1.0 → v2.5.02022-01-17

v2.7.0 → v3.0.02024-05-08

v2.8.0 → v3.1.12025-09-22

v2.8.1 → v3.1.32025-09-24

PHP version history (6 changes)0.1.0PHP ^5.5|^7

v0.4.0PHP ^5.3|^7

v2.0.0PHP ^7

v2.3.0PHP ^7|^8

v1.x-devPHP ^5.3|^7|^8

v3.0.0PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/05d241256cda885139a5697d3bb536b5cec3b430c1adb9c524bf92a37a55758d?d=identicon)[paragonie-scott](/maintainers/paragonie-scott)

---

Top Contributors

[![paragonie-security](https://avatars.githubusercontent.com/u/15914520?v=4)](https://github.com/paragonie-security "paragonie-security (103 commits)")[![paragonie-scott](https://avatars.githubusercontent.com/u/11591518?v=4)](https://github.com/paragonie-scott "paragonie-scott (26 commits)")[![TimWolla](https://avatars.githubusercontent.com/u/209270?v=4)](https://github.com/TimWolla "TimWolla (16 commits)")[![peldax](https://avatars.githubusercontent.com/u/10790033?v=4)](https://github.com/peldax "peldax (2 commits)")[![inkeliz](https://avatars.githubusercontent.com/u/4644332?v=4)](https://github.com/inkeliz "inkeliz (1 commits)")[![jdreesen](https://avatars.githubusercontent.com/u/424602?v=4)](https://github.com/jdreesen "jdreesen (1 commits)")[![krsriq](https://avatars.githubusercontent.com/u/2337648?v=4)](https://github.com/krsriq "krsriq (1 commits)")[![michaeldyrynda](https://avatars.githubusercontent.com/u/558441?v=4)](https://github.com/michaeldyrynda "michaeldyrynda (1 commits)")[![nikanderson](https://avatars.githubusercontent.com/u/17752261?v=4)](https://github.com/nikanderson "nikanderson (1 commits)")[![SharkMachine](https://avatars.githubusercontent.com/u/7488694?v=4)](https://github.com/SharkMachine "SharkMachine (1 commits)")[![systemsolutionweb](https://avatars.githubusercontent.com/u/88460896?v=4)](https://github.com/systemsolutionweb "systemsolutionweb (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![Chris8934](https://avatars.githubusercontent.com/u/44963939?v=4)](https://github.com/Chris8934 "Chris8934 (1 commits)")[![tvlooy](https://avatars.githubusercontent.com/u/391674?v=4)](https://github.com/tvlooy "tvlooy (1 commits)")[![erikn69](https://avatars.githubusercontent.com/u/4933954?v=4)](https://github.com/erikn69 "erikn69 (1 commits)")[![Grundik](https://avatars.githubusercontent.com/u/220951?v=4)](https://github.com/Grundik "Grundik (1 commits)")[![hansott](https://avatars.githubusercontent.com/u/3886384?v=4)](https://github.com/hansott "hansott (1 commits)")

---

Tags

base16base32base32hexbase64base64-urlsafebase64urlcache-timing-safecharacter-encodingconstant-timeencodinghexadecimalphprfc-4648url-safeurlsafeencodingbase64rfc4648base32hexbase16bin2hexhex2binbase64\_encodebase64\_decodebase32\_encodebase32\_decode

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[spomky-labs/base64url

Base 64 URL Safe Encoding/Decoding PHP Library

15439.5M49](/packages/spomky-labs-base64url)[christian-riesen/base32

Base32 encoder/decoder according to RFC 4648

13331.8M61](/packages/christian-riesen-base32)[xobotyi/basen

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

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

Facilitating the process of altering string encoding in PHP.

698.7M43](/packages/paquettg-string-encode)[ademarre/binary-to-text-php

Collection of binary-to-text encoding utilities for PHP. Includes Base32 support and much more.

40165.8k](/packages/ademarre-binary-to-text-php)[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

631.1M10](/packages/ssnepenthe-color-utils)

PHPackages © 2026

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