PHPackages                             covaleski/data-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. covaleski/data-encoding

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

covaleski/data-encoding
=======================

Data encoding and decoding.

v1.0.0(2y ago)0261MITPHP

Since Oct 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/covaleski/data-encoding)[ Packagist](https://packagist.org/packages/covaleski/data-encoding)[ RSS](/packages/covaleski-data-encoding/feed)WikiDiscussions main Synced 1mo ago

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

Data Encoding
=============

[](#data-encoding)

[![License: MIT](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](LICENSE)

PHP complete implementation of [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648). Provides methods for data encoding and decoding in multiple bases - including custom encoding.

Uses bitwise operations to provide faster processing than string functions would do.

Note that both base16 and base64 encoding styles are already natively supported by PHP through `base64_encode`/`base64_decode` and `bin2hex`/`hex2bin` functions.

1 Installation
--------------

[](#1-installation)

```
composer require covaleski/data-encoding
```

2 Usage
-------

[](#2-usage)

The following encoding styles - defined in RFC 4648 - are natively provided by this library:

- base16:
    - Encoding with case-insensitive 16 character alphabet;
    - Available through `Base16` class;
- base32:
    - Encoding with case-insensitive 32 character alphabet;
    - Available through `Base32` class;
- base32hex:
    - Base32 with base16 extended alphabet;
    - Available through `Base32Hex` class;
- base64:
    - Encoding with case-sensitive 64 character alphabet;
    - Available through `Base64` class;
- base64url:
    - Base64 with URL/filename safe character alphabet.
    - Available through `Base64Url` class;

You can easily extend the `Encoder` class to create custom encoding styles. See [2.3 Creating custom encodings](#23-creating-custom-encodings).

### 2.1 Encoding

[](#21-encoding)

Encoding is available through the `encode()` static method in all encoder classes listed above.

```
use Covaleski\DataEncoding\Base32;

$encoded = Base32::encode('Dunder Mifflin Paper Company, Inc.');
// Will produce: IR2W4ZDFOIQE22LGMZWGS3RAKBQXAZLSEBBW63LQMFXHSLBAJFXGGLQ=
```

### 2.2 Decoding

[](#22-decoding)

Decoding is available through the `decode()` static method in all encoder classes listed above.

```
use Covaleski\DataEncoding\Base32;

$decoded = Base32::decode('4WGZPZF2VTULPLY=');
// Will produce: 南京路
```

### 2.3 Creating custom encodings

[](#23-creating-custom-encodings)

For custom encoding, you must extend the `Encoder` class and set the following properties (all static):

- `int $base`:
    - Required;
    - Is the number of characters the alphabet should have;
    - Must be a power of 2;
- `array $alphabet`:
    - Required;
    - Is a list with all the alphabet's characters;
    - Must have unique characters only;
    - Is accessed with indexes generated by the bits of input data;
- `bool $isCaseSensitive`:
    - Required;
    - Defines whether the alphabet is case-sensitive;
    - Example: if not case-sensitive, decoding `MZXW6===` and `mzxw6===` would generate identical results;
- `string $alphabetEncoding`:
    - Optional - defaults to "ASCII";
    - Is the encoding system used by the alphabet characters;
    - Non-ASCII alphabets MUST have their encoding explicitly defined;
    - Is used to build and split the encoded string;
- `string $paddingCharacter`:
    - Optional - defaults to "=";
    - Is used to pad encoded strings;
    - Must not exist in the alphabet.

Example with ASCII alphabet:

```
class Base4 extends Encoder
{
    protected static array $alphabet = [
        'A', 'B', 'C', 'D',
    ];
    protected static int $base = 4;
    protected static bool $isCaseSensitive = true;
}

$encoded = Base8Emoji::encode('foo');
// Will produce: BCBCBCDDBCDD
```

Example with Unicode alphabet:

```
use Covaleski\DataEncoding\Encoder;

class Base8Emoji extends Encoder
{
    protected static array $alphabet = [
        '😎', '😔', '😳', '💀', '🤡', '👀', '✊', '💅',
    ];
    protected static int $base = 8;
    protected static string $alphabetEncoding = 'UTF-8';
    protected static bool $isCaseSensitive = false;
}

$encoded = Base8Emoji::encode('foo');
// Will produce: 💀😔🤡✊💅👀👀💅
```

3 Testing
---------

[](#3-testing)

Tests were made with PHPUnit. Use the following command to run all of them.

```
./vendor/bin/phpunit
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

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

936d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35d4c539af573768e021fd53113a4ef76bd133b2988325f35b8ab0a82a2dbf9c?d=identicon)[covaleski](/maintainers/covaleski)

---

Top Contributors

[![covaleski](https://avatars.githubusercontent.com/u/99929442?v=4)](https://github.com/covaleski "covaleski (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/covaleski-data-encoding/health.svg)

```
[![Health](https://phpackages.com/badges/covaleski-data-encoding/health.svg)](https://phpackages.com/packages/covaleski-data-encoding)
```

###  Alternatives

[zumba/symbiosis

Symbiosis, event structure for bootstrapping plugins.

1360.4k1](/packages/zumba-symbiosis)

PHPackages © 2026

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