PHPackages                             tuupola/base58 - 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/base58

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

tuupola/base58
==============

Base58 encoder and decoder for arbitrary data

2.2.0(4mo ago)56609.6k—4.4%920MITPHPPHP ^7.2|^8.0CI failing

Since Jun 9Pushed 4mo ago1 watchersCompare

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

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

Base58
======

[](#base58)

This library implements Base58 encoding. In addition to integers it can encode and decode any arbitrary data. That said, Base58 is well suited for decoding big integers but is not designed to decode long portions of binary data.

[![Latest Version](https://camo.githubusercontent.com/0d8edfb2b32a8aaa415b41d8fe0401757193bf0f97abbd285dc5e70742949256/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747575706f6c612f6261736535382e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tuupola/base58)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/f2d8b1ef4629111837f047ba1842dcb5994d77ee6648ee34ae42badbf6925e7d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f747575706f6c612f6261736535382f74657374732e796d6c3f6272616e63683d322e78267374796c653d666c61742d737175617265)](https://github.com/tuupola/base58/actions)[![Coverage](https://camo.githubusercontent.com/ca5425fcd6997e94288e8c1598538d7791c8dac7b5255dd3523f0cfe3538f8e5/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f747575706f6c612f6261736535382e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/tuupola/base58)

Install
-------

[](#install)

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

```
$ composer require tuupola/base58
```

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

```
$ composer require "tuupola/base58:^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.

```
$base58 = new Tuupola\Base58;

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

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

```
$integer = $base58->encodeInteger(987654321); /* 1TFvCj */
print $base58->decodeInteger("1TFvCj", true); /* 987654321 */
```

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

```
$string = $base58->encode("987654321"); /* gE62MGeOBMPt */
$integer = $base58->encodeInteger(987654321); /* 1TFvCj */
```

Character sets
--------------

[](#character-sets)

By default Base58 uses GMP style character set. Shortcuts are provided for [Bitcoin](https://github.com/bitcoin/bitcoin/blob/master/src/base58.cpp), [Flickr](https://www.flickr.com/groups/api/discuss/72157616713786392/), [Ripple](https://wiki.ripple.com/Accounts) and [IPFS](https://github.com/richardschneider/net-ipfs-core#base58) character sets. You can also use any custom 58 characters.

```
use Tuupola\Base58;

print Base58::GMP /* 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv */
print Base58::BITCOIN /* 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz */
print Base58::FLICKR /* 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ */
print Base58::RIPPLE /* rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz */
print Base58::IPFS /* 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz */

$default = new Base58(["characters" => Base58::GMP]);
$bitcoin = new Base58(["characters" => Base58::BITCOIN]);
print $default->encode("Hello world!"); /* 1LDlk6QWOejX6rPrJ */
print $bitcoin->encode("Hello world!"); /* 2NEpo7TZRhna7vSvL */
```

Base58Check support
-------------------

[](#base58check-support)

This library supports the [Base58Check](https://en.bitcoin.it/wiki/Base58Check_encoding) encoding used in Bitcoin addresses. Decoding validates both version and the checksum. If either of them fails a `RuntimeException` will be thrown;

```
use Tuupola\Base58;

$base58check = new Base58([
    "characters" => Base58::BITCOIN,
    "check" => true,
    "version" => 0x00
]);

print $base58check->encode("Hello world!"); /* 19wWTEnNTWna86WmtFsTAr5 */

try {
    $base58check->decode("19wWTEnNTWna86WmtFsTArX");
} catch (RuntimeException $exception) {
    /* Checksum "84fec52c" does not match the expected "84fec512" */
    print $exception->getMessage();
}
```

Speed
-----

[](#speed)

Install GMP if you can. It is much faster pure PHP encoder. Below benchmarks are for encoding `random_bytes(128)` data. BCMatch encoder is also included but it is mostly just a curiosity. It is too slow to be usable.

```
$ vendor/bin/phpbench run benchmarks/ --report=default

+-----------------------+------------------+--------------+
| subject               | mean             | diff         |
+-----------------------+------------------+--------------+
| benchGmpEncoder       | 101,832.994ops/s | 0.00%        |
| benchGmpEncoderCustom | 97,656.250ops/s  | +4.28%       |
| benchPhpEncoder       | 305.913ops/s     | +33,188.19%  |
| benchBcmathEncoder    | 32.457ops/s      | +313,643.79% |
+-----------------------+------------------+--------------+

```

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

[](#static-proxy)

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

```
use Tuupola\Base58Proxy as Base58;

$encoded = Base58::encode(random_bytes(128));
$decoded = Base58::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.md) for more information.

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance75

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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 ~241 days

Recently: every ~619 days

Total

14

Last Release

129d ago

Major Versions

0.4.0 → 1.0.02019-03-30

1.x-dev → 2.0.02019-03-31

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

0.2.0PHP ^5.6 || ^7.0

0.2.2PHP ^5.6|^7.0

2.0.0PHP ^7.1

2.1.0PHP ^7.1|^8.0

2.2.0PHP ^7.2|^8.0

### 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 (97 commits)")[![boppy](https://avatars.githubusercontent.com/u/749141?v=4)](https://github.com/boppy "boppy (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

base58

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[spatie/macroable

A trait to dynamically add methods to a class

72759.6M64](/packages/spatie-macroable)[google/longrunning

Google LongRunning Client for PHP

5771.7M4](/packages/google-longrunning)[consolidation/filter-via-dot-access-data

This project uses dflydev/dot-access-data to provide simple output filtering for applications built with annotated-command / Robo.

4646.9M13](/packages/consolidation-filter-via-dot-access-data)[xobotyi/basen

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

1219.6k](/packages/xobotyi-basen)

PHPackages © 2026

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