bakame / aide-base32
base32 encoding and decoding using functions in PHP
Fund package maintenance!
nyamsprod
Installs: 2 414
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75.0
- phpstan/phpstan: ^2.1.17
- phpstan/phpstan-deprecation-rules: ^2.0.3
- phpstan/phpstan-phpunit: ^2.0.6
- phpstan/phpstan-strict-rules: ^2.0.4
- phpunit/phpunit: ^10.5.15 || ^11.5.22 || ^12.2.1
- symfony/var-dumper: ^6.4.21
This package is auto-updated.
Last update: 2025-06-08 13:47:52 UTC
README
functions or class to allow encoding or decoding strings using RFC4648 base32 algorithm.
Installation
Composer
composer require bakame-php/aide-base32
System Requirements
You need:
- PHP >= 8.1 but the latest stable version of PHP is recommended
Usage
The package provides a userland base32 encoding and decoding mechanism.
base32_encode(string $decoded, string $alphabet = PHP_BASE32_ASCII, $padding = '='): string base32_decode(string $encoded, string $alphabet = PHP_BASE32_ASCII, $padding = '=', bool $strict = false): string|false
Parameters:
$decoded
: the string to encode forbase32_encode
$encoded
: the string to decode forbase32_decode
$alphabet
: the base32 alphabet, by defaultPHP_BASE32_ASCII
.$padding
: the padding character$strict
: tell whether we need to perform strict decoding or not
If the strict parameter is set to true
then the base32_decode
function will return false
- if encoded sequence length is invalid
- if the input contains character from outside the base64 alphabet.
- if padding is invalid
- if encoded characters do not follow the alphabet lettering.
otherwise listed constraints are silently ignored or discarded.
RFC4648 support
- If
$alphabet
isPHP_BASE32_ASCII
and the$padding
is=
, conversion is performed per RFC4648 US-ASCII standard. - If
$alphabet
isPHP_BASE32_HEX
and the$padding
is=
, conversion is performed per RFC4648 HEX standard.
You MAY provide your own alphabet of 32 characters and your own padding character.
<?php base32_encode('Bangui'); // returns 'IJQW4Z3VNE======' base32_decode('IJQW4Z3VNE======'); // returns 'Bangui' base32_decode('IJQW4Z083VNE======'); // returns 'Bangui' base32_decode(encoded:'IJQW4Z083VNE======', strict: true) // return false base32_encode('Bangui', PHP_BASE32_HEX, '*'); // returns '89GMSPRLD4******' base32_decode('89GMSPRLD4******', PHP_BASE32_HEX, '*'); // returns 'Bangui'