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

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

bakame/aide-base32
==================

base32 encoding and decoding using functions in PHP

22.6k1PHPCI passing

Since Dec 10Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/bakame-php/aide-base32)[ Packagist](https://packagist.org/packages/bakame/aide-base32)[ RSS](/packages/bakame-aide-base32/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

Aide for base32 encoding and decoding
=====================================

[](#aide-for-base32-encoding-and-decoding)

functions or class to allow encoding or decoding strings using [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648) base32/base16 algorithm. This is a quick polyfill for the proposed RFC around [adding an encoding API to PHP](https://wiki.php.net/rfc/data_encoding_api)

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require bakame-php/aide-base32

```

### System Requirements

[](#system-requirements)

You need:

- **PHP &gt;= 8.1** but the latest stable version of PHP is recommended

Usage
-----

[](#usage)

The package provides a userland base32 encoding and decoding mechanism.

```
use Encoding\Base32;
use Encoding\DecodingMode;
use Encoding\PaddingMode;

base32_encode(string $data, Base32 $variant = Base32::Ascii, PaddingMode $paddingMode = PaddingMode::VariantControlled): string
base32_decode(string $data, Base32 $variant = Base32::Ascii, DecodingMode $decodingMode = DecodingMode::Strict): string
```

#### Parameters:

[](#parameters)

- `$data` : the string to encode or decode
- `$variant` : the base32 alphabet represented as an Enum.
- `$paddingMode` : the padding mode
- `$decodingMode` : Strict (follow the RFC) or Forgiving

If the `$decodingMode` parameter is set to `Strict` then the `base32_decode` function will throw

- 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.

#### Examples

[](#examples)

```
