Pretty lightweight implementation of Base58 encoding and deconding algorithms written in PHP.
Install with composer.
$ composer require sulaco-tech/base58
This branch requires PHP 7.0 or up.
$base58 = new SulacoTech\Base58();
$data = "Hello World!";
$encoded = $base58->encode($data); // "2NEpo7TZRRrLZSi2U"
$decoded = $base58->decode($encoded); // "Hello World!"
Encoder support few predefined charset sets for coding algorithms:
You can also use any custom 58 characters. By default the encoder uses IPFS style character set.
use SulacoTech\Base58;
print Base58::CHARSET_GMP;
// 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv
print Base58::CHARSET_BITCOIN;
// 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
print Base58::CHARSET_FLICKR;
// 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
print Base58::CHARSET_RIPPLE;
// rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz
print Base58::CHARSET_IPFS;
// 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
$base58 = new Base58(Base58::CHARSET_FLICKR);
$data = "Hello World!";
$encoded = $base58->encode($data); // "2nePN7syqqRkyrH2t"
$decoded = $base58->decode($encoded); // "Hello World!"
You can run tests with external (global) installation of PHPUnit.
$ phpunit tests
This branch was tested on PHP:
- 7.0.12
- 7.1.9
- 7.2.17
- 7.4.3
This library is license under the MIT License (MIT). Please see License File for more information.