PHPackages                             tuupola/base32 - 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. tuupola/base32

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

tuupola/base32
==============

Base32 encoder and decoder for arbitrary data

2.0.1(6mo ago)15616.7k↓38%26MITPHPPHP ^7.1|^8.0CI failing

Since Jun 26Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/tuupola/base32)[ Packagist](https://packagist.org/packages/tuupola/base32)[ Docs](https://github.com/tuupola/base32)[ RSS](/packages/tuupola-base32/feed)WikiDiscussions 2.x Synced 2d ago

READMEChangelogDependencies (5)Versions (16)Used By (6)

Base32
======

[](#base32)

This library implements Base32 encoding. In addition to integers it can encode and decode any arbitrary data.

[![Latest Version](https://camo.githubusercontent.com/deb9277f89691fa8d4258f30569aebec11eae258be92765714fb8ab5f327f633/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747575706f6c612f6261736533322e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tuupola/base32)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/2244ac099235316c9d774f0c6c571cdef8d76d7a4cbb8546ddfbd7ea06744838/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f747575706f6c612f6261736533322f74657374732e796d6c3f6272616e63683d322e78267374796c653d666c61742d737175617265)](https://github.com/tuupola/base32/actions)[![Coverage](https://camo.githubusercontent.com/f5537c0ab9f759ad1176ca9607f8debee9bd3cb5c443763e09328c67301438ab/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f747575706f6c612f6261736533322e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/tuupola/base32)

Install
-------

[](#install)

Install with [composer](https://getcomposer.org/).

```
$ composer require tuupola/base32
```

This branch requires PHP 7.1 or up. The older 1.x branch supports also PHP 5.6 and 7.0.

```
$ composer require "tuupola/base32:^1.0"
```

Usage
-----

[](#usage)

This package has both pure PHP and [GMP](http://php.net/manual/en/ref.gmp.php) based encoders. By default encoder and decoder will use GMP functions if the extension is installed. If GMP is not available pure PHP encoder will be used instead.

```
$base32 = new Tuupola\Base32;

$encoded = $base32->encode(random_bytes(128));
$decoded = $base32->decode($encoded);
```

If you are encoding to and from integer use the implicit `decodeInteger()` and `encodeInteger()` methods.

```
$integer = $base32->encodeInteger(987654321); /* 5N42FR== */
print $base32->decodeInteger("5N42FR=="); /* 987654321 */
```

Also note that encoding a string and an integer will yield different results.

```
$integer = $base32->encodeInteger(987654321); /* 5N42FR== */
$string = $base32->encode("987654321"); /* FHE4DONRVGQZTEMI= */
```

Encoding Modes
--------------

[](#encoding-modes)

### RCF4684

[](#rcf4684)

[RCF4684](https://tools.ietf.org/html/rfc4648) is the default when encoder is created without passing any parameters. Explicit parameters shown below.

```
use Tuupola\Base32;

$base32 = new Base32([
    "characters" => Base32::RFC4648,
    "padding" => "="
]);

print $base32->encode("Hello world!"); /* JBSWY3DPEB3W64TMMQQQ==== */
```

### RCF4684 HEX

[](#rcf4684-hex)

[RCF4684 base32hex](https://tools.ietf.org/html/rfc4648) encoding is identical to previous, except for the character set. This encoding is lexically sortable.

```
$base32hex = new Base32([
    "characters" => Base32::HEX,
    "padding" => "="
]);

print $base32->encode("Hello world!"); /* 91IMOR3F41RMUSJCCGGG==== */
```

### GMP

[](#gmp)

[GMP](http://php.net/manual/en/book.gmp.php) encoding is identical to previous. Example below is shown with padding disabled.

```
$gmp = new Base32([
    "characters" => Base32::GMP,
    "padding" => false
]);

print $gmp->encode("Hello world!"); /* 91IMOR3F41RMUSJCCGGG */
```

### Crockford's Base32

[](#crockfords-base32)

When decoding, upper and lower case letters are accepted, and i and l will be treated as 1 and o will be treated as 0. When encoding, only upper case letters are used. Hyphens are ignored during decoding.

```
$crockford = new Base32([
    "characters" => Base32::CROCKFORD,
    "padding" => false,
    "crockford" => true,
]);

print $crockford->encode("Hello world!"); /* 91JPRV3F41VPYWKCCGGG */
print $crockford->decode("91JPRV3F41VPYWKCCGGG"); /* Hello world! */
print $crockford->decode("91jprv3f41vpywkccggg"); /* Hello world! */
print $crockford->decode("9ljprv3f4lvpywkccggg"); /* Hello world! */
```

### Z-base-32 \[WIP\]

[](#z-base-32-wip)

Character Sets
--------------

[](#character-sets)

By default Base32 uses RFC4648 character set. Shortcut is provided for other commonly used character sets. You can also use any custom character set of 32 unique characters.

```
use Tuupola\Base32;

print Base32::CROCKFORD; /* 0123456789ABCDEFGHJKMNPQRSTVWXYZ */
print Base32::RFC4648; /* ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 */
print Base32::ZBASE32; /* ybndrfg8ejkmcpqxot1uwisza345h769 */
print Base32::GMP; /* 0123456789ABCDEFGHIJKLMNOPQRSTUV */
print Base32::HEX; /* 0123456789ABCDEFGHIJKLMNOPQRSTUV */

$default = new Base32(["characters" => Base32::RFC4648]);
$crockford = new Base32(["characters" => Base32::CROCKFORD]);
print $default->encode("Hello world!"); /* JBSWY3DPEB3W64TMMQQQ==== */
print $inverted->encode("Hello world!"); /* 91JPRV3F41VPYWKCCGGG==== */
```

Speed
-----

[](#speed)

Install GMP if you can. It is reasonably faster pure PHP encoder. Below benchmarks are for encoding `random_bytes(128)` data.

```
$ make benchmark

benchmark: Base32Bench
+-----------------------+----------------+-------+
| subject               | mean           | diff  |
+-----------------------+----------------+-------+
| benchGmpEncoder       | 8,361.204ops/s | 1.00x |
| benchGmpEncoderCustom | 8,393.487ops/s | 1.00x |
| benchPhpEncoder       | 6,881.365ops/s | 1.22x |
+-----------------------+----------------+-------+

```

Static Proxy
------------

[](#static-proxy)

If you prefer to use static syntax use the provided static proxy.

```
use Tuupola\Base32Proxy as Base32;

$encoded = Base32::encode(random_bytes(128));
$decoded = Base32::decode($encoded);
```

Testing
-------

[](#testing)

You can run tests either manually or automatically on every code change. Automatic tests require [entr](http://entrproject.org/) to work.

```
$ make test
```

```
$ brew install entr
$ make watch
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance69

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 93.5% 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 ~347 days

Recently: every ~544 days

Total

10

Last Release

165d ago

Major Versions

0.3.0 → 1.x-dev2020-02-05

1.0.0 → 2.0.02020-11-19

2.0.0 → 3.x-dev2025-12-12

PHP version history (3 changes)0.1.0PHP ^5.6 || ^7.0

2.0.0PHP ^7.1|^8.0

3.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3325405a7d8a43bc40dd0e760a4b7f268fba32a7150cf0327f64f13d1661df0b?d=identicon)[tuupola](/maintainers/tuupola)

---

Top Contributors

[![tuupola](https://avatars.githubusercontent.com/u/21913?v=4)](https://github.com/tuupola "tuupola (72 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (4 commits)")[![hapidjus](https://avatars.githubusercontent.com/u/5553121?v=4)](https://github.com/hapidjus "hapidjus (1 commits)")

---

Tags

base32

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tuupola-base32/health.svg)

```
[![Health](https://phpackages.com/badges/tuupola-base32/health.svg)](https://phpackages.com/packages/tuupola-base32)
```

###  Alternatives

[paragonie/constant_time_encoding

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

908363.2M191](/packages/paragonie-constant-time-encoding)[christian-riesen/base32

Base32 encoder/decoder according to RFC 4648

13333.9M74](/packages/christian-riesen-base32)[ademarre/binary-to-text-php

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

39172.5k](/packages/ademarre-binary-to-text-php)[skleeschulte/base32

Base32 encoding and decoding class (RFC 4648, RFC 4648 extended hex, Crockford, z-base-32/Zooko).

17323.3k9](/packages/skleeschulte-base32)[dflydev/base32-crockford

Encode/decode numbers using Douglas Crockford's Base32 Encoding

14416.4k1](/packages/dflydev-base32-crockford)[xobotyi/basen

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

1220.4k](/packages/xobotyi-basen)

PHPackages © 2026

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