sulaco-tech/base58

Pretty lightweight implementation of Base58 encoding and deconding algorithms written in PHP.

1.0.0 2020-03-18 06:47 UTC

This package is auto-updated.

Last update: 2024-04-18 16:44:42 UTC


README

Pretty lightweight implementation of Base58 encoding and deconding algorithms written in PHP.

Install

Install with composer.

$ composer require sulaco-tech/base58

Requirements

This branch requires PHP 7.0 or up.

Usage

$base58 = new SulacoTech\Base58();

$data = "Hello World!";
$encoded = $base58->encode($data); // "2NEpo7TZRRrLZSi2U"
$decoded = $base58->decode($encoded); // "Hello World!"

Character sets

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!"

Testing

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

License

This library is license under the MIT License (MIT). Please see License File for more information.