PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Andre Polykanine A.K.A. Menelion Elensúlë   Oire Base64   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Oire Base64
URL safe encoding and decoding of data with Base64
Author: By
Last change: Sunset the library in favor of Iridium
Remove PhpStan support
Add PHPStan support

* Add PHPStan support

* Update year
Fix workflow name
Remove Travis CI and add Github actions

* Remove Travis and add Github Actions
* fix github actions hopefully
Prepare for version 2

* Update dependencies
* Standardize namespaces
* Improve Readme
Fix URLs to Build status in Readme
Prepare for version 1.2

* Add proper exceptions;
* Normalized code style;
* Standardized tests.
Date: 15 days ago
Size: 2,202 bytes
 

 

Contents

Class file image Download

Oirë Base64, URL-safe Base64 Handling

Note! This library is not maintained anymore.

Please use Iridium security library instead.

Latest Version on Packagist MIT License

Encodes data to Base64 URL-safe way and decodes encoded data.

Requirements

This library requires PHP 7.3 or above.

Installation

Install via Composer:

composer require oire/base64

Running Tests

Run ./vendor/bin/phpunit in the project directory.

Compatibility with Earlier Versions of PHP

If you want a version compatible with PHP 7.1.2, please install version 1 instead:

composer require "oire/base64 ^1"

Usage Examples

use Oire\Base64\Base64;
use Oire\Base64\Exception\Base64Exception;

$text = "The quick brown fox jumps over the lazy dog";
$encoded = Base64::encode($text);
echo $encoded.PHP_EOL;

This will output:

VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw

By default, the encode() method truncates padding = signs as PHP?s built-in decoder handles this correctly. However, if the second parameter is given and set to true, = signs will be replaced with tildes (~), i.e.:

$encoded = Base64::encode($text, true);
echo $encoded.PHP_EOL;

This will output:

VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw~~

To decode the data, simply call Base64::decode():

$encoded = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw";

try {
    $decoded = Base64::decode($encoded);
} catch(Base64Exception $e) {
    // Handle errors
}

echo $decoded.PHP_EOL;

This will output:

The quick brown fox jumps over the lazy dog

License

Copyright © 2017-2021, Andre Polykanine also known as Menelion Elensúlë, The Magical Kingdom of Oirë. This software is licensed under an MIT license.