├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── src ├── Base64.php └── Throwable │ ├── DecodingError.php │ ├── EncodingError.php │ ├── Error.php │ └── Exception.php └── tests └── index.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = tab 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | indent_style = space 13 | indent_size = 4 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .idea/ 3 | 4 | # Composer 5 | vendor/ 6 | composer.phar 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) delight.im (https://www.delight.im/) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP-Base64 2 | 3 | Simple and convenient Base64 encoding and decoding for PHP 4 | 5 | ## Requirements 6 | 7 | * PHP 5.3.0+ 8 | 9 | ## Installation 10 | 11 | 1. Include the library via Composer [[?]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md): 12 | 13 | ``` 14 | $ composer require delight-im/base64 15 | ``` 16 | 17 | 1. Include the Composer autoloader: 18 | 19 | ```php 20 | require __DIR__ . '/vendor/autoload.php'; 21 | ``` 22 | 23 | ## Usage 24 | 25 | ### Standard 26 | 27 | * Encoding data 28 | 29 | ```php 30 | \Delight\Base64\Base64::encode('Gallia est omnis divisa in partes tres'); 31 | // string(52) "R2FsbGlhIGVzdCBvbW5pcyBkaXZpc2EgaW4gcGFydGVzIHRyZXM=" 32 | ``` 33 | 34 | * Decoding data 35 | 36 | ```php 37 | \Delight\Base64\Base64::decode('R2FsbGlhIGVzdCBvbW5pcyBkaXZpc2EgaW4gcGFydGVzIHRyZXM='); 38 | // string(38) "Gallia est omnis divisa in partes tres" 39 | ``` 40 | 41 | ### URL-safe 42 | 43 | * Encoding data 44 | 45 | ```php 46 | \Delight\Base64\Base64::encodeUrlSafe('πάντα χωρεῖ καὶ οὐδὲν μένει …'); 47 | // string(80) "z4DOrM69z4TOsSDPh8-Jz4HOteG_liDOus6x4b22IM6_4b2QzrThvbLOvSDOvM6tzr3Otc65IOKApg~~" 48 | ``` 49 | 50 | * Decoding data 51 | 52 | ```php 53 | \Delight\Base64\Base64::decodeUrlSafe('z4DOrM69z4TOsSDPh8-Jz4HOteG_liDOus6x4b22IM6_4b2QzrThvbLOvSDOvM6tzr3Otc65IOKApg~~'); 54 | // string(58) "πάντα χωρεῖ καὶ οὐδὲν μένει …" 55 | ``` 56 | 57 | ### URL-safe without padding 58 | 59 | * Encoding data 60 | 61 | ```php 62 | \Delight\Base64\Base64::encodeUrlSafeWithoutPadding('πάντα χωρεῖ καὶ οὐδὲν μένει …'); 63 | // string(78) "z4DOrM69z4TOsSDPh8-Jz4HOteG_liDOus6x4b22IM6_4b2QzrThvbLOvSDOvM6tzr3Otc65IOKApg" 64 | ``` 65 | 66 | * Decoding data 67 | 68 | ```php 69 | \Delight\Base64\Base64::decodeUrlSafeWithoutPadding('z4DOrM69z4TOsSDPh8-Jz4HOteG_liDOus6x4b22IM6_4b2QzrThvbLOvSDOvM6tzr3Otc65IOKApg'); 70 | // string(58) "πάντα χωρεῖ καὶ οὐδὲν μένει …" 71 | ``` 72 | 73 | ## Specifications 74 | 75 | * [RFC 4648](https://tools.ietf.org/html/rfc4648) 76 | * [RFC 3548](https://tools.ietf.org/html/rfc3548) 77 | * [RFC 2045](https://tools.ietf.org/html/rfc2045) 78 | * [RFC 1421](https://tools.ietf.org/html/rfc1421) 79 | * [RFC 7515](https://tools.ietf.org/html/rfc7515) 80 | 81 | ## Contributing 82 | 83 | All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed. 84 | 85 | ## License 86 | 87 | This project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT). 88 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "delight-im/base64", 3 | "description": "Simple and convenient Base64 encoding and decoding for PHP", 4 | "require": { 5 | "php": ">=5.3.0" 6 | }, 7 | "type": "library", 8 | "keywords": [ "base64", "base-64", "encode", "decode", "encoding", "decoding", "url-safe", "url" ], 9 | "homepage": "https://github.com/delight-im/PHP-Base64", 10 | "license": "MIT", 11 | "autoload": { 12 | "psr-4": { 13 | "Delight\\Base64\\": "src/" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "d69f90769e62bab4c7f053c4a3030138", 8 | "packages": [], 9 | "packages-dev": [], 10 | "aliases": [], 11 | "minimum-stability": "stable", 12 | "stability-flags": [], 13 | "prefer-stable": false, 14 | "prefer-lowest": false, 15 | "platform": { 16 | "php": ">=5.3.0" 17 | }, 18 | "platform-dev": [] 19 | } 20 | -------------------------------------------------------------------------------- /src/Base64.php: -------------------------------------------------------------------------------- 1 |