PHPackages                             antikirra/base64url - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. antikirra/base64url

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

antikirra/base64url
===================

2.1.1(6mo ago)03181MITPHPPHP ^5.6 || ^7.0 || ^8.0

Since May 24Pushed 6mo ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (5)Used By (1)

Base64URL | URL-Safe Base64 Encoding
====================================

[](#base64url--url-safe-base64-encoding)

[![Packagist Dependency Version](https://camo.githubusercontent.com/b3faa16492c5cfd8042bf4a2113430ce1a75d14090feab9e6e6ad2826407ef79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616e74696b697272612f62617365363475726c2f706870)](https://camo.githubusercontent.com/b3faa16492c5cfd8042bf4a2113430ce1a75d14090feab9e6e6ad2826407ef79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616e74696b697272612f62617365363475726c2f706870)[![Packagist Version](https://camo.githubusercontent.com/c4364939c7f907f9b04fee7b54688e0a1ec6a92d598e887b1e6504e2c1cb8946/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e74696b697272612f62617365363475726c)](https://camo.githubusercontent.com/c4364939c7f907f9b04fee7b54688e0a1ec6a92d598e887b1e6504e2c1cb8946/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e74696b697272612f62617365363475726c)[![Code Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)

**Ultra-lightweight PHP library for URL-safe base64 encoding and decoding.** Perfect for JWT tokens, URL parameters, API keys, and any scenario requiring base64 encoding without URL-unsafe characters (+, /, =).

Install
-------

[](#install)

```
composer require antikirra/base64url:^2.0
```

Why Base64URL?
--------------

[](#why-base64url)

- ✨ **URL-Safe** - No special characters that need URL encoding
- 🔧 **RFC 4648 Compliant** - Follows official base64url specification
- ⚡ **Blazing Fast** - Minimal overhead, optimized string operations
- 🎯 **Drop-in Replacement** - Simple API, easy migration from base64\_encode/decode
- 📦 **Lightweight** - Just 2 functions, zero dependencies
- 🚀 **Production Ready** - Battle-tested in JWT and API implementations

Features
--------

[](#features)

- **URL-Safe Encoding**: Replaces `+` with `-` and `/` with `_`, removes padding `=`
- **Input Validation**: Strict validation prevents invalid characters in decoding
- **UTF-8 Support**: Handles multibyte characters correctly (Chinese, Korean, Japanese, etc.)
- **Binary Safe**: Works with any binary data, not just text
- **Legacy Compatible**: Works with PHP 5.6+ through PHP 8.4
- **Zero Dependencies**: No external libraries or extensions required
- **100% Test Coverage**: Fully tested with comprehensive test suite

Perfect for
-----------

[](#perfect-for)

- **JWT Tokens**: Encoding JWT payloads and signatures
- **URL Parameters**: Safely encode data in query strings
- **API Keys**: Generate URL-safe API tokens and keys
- **OAuth**: State parameters and authorization codes
- **File Names**: Encode data for use in file names
- **Cookies**: Store encoded data in cookies without escaping

Requirements
------------

[](#requirements)

- **PHP**: 5.6 or higher
- **Extensions**: None (uses only core PHP functions)
- **Dependencies**: Zero

Basic usage
-----------

[](#basic-usage)

```
