beorn/base64url-tools

Base64 URL-safe encoder/decoder. Also generates random tokens.

v2.0.1 2020-11-09 09:34 UTC

This package is auto-updated.

Last update: 2024-05-09 23:10:36 UTC


README

This library provides a simple URL-safe Base64 encoder/decoder. Nothing fancy, just PHP's standard base64_encode() and base64_decode() functions converted to a URL- and filename-safe alphabet as defined in RFC 4648. None of this is new, I just wanted to have a convenient place to bundle these tools into my projects.

Encoding/Decoding Data

Simply pass your raw or encoded data into the appropriate function:

Base64Url::encode("Hello, world!") => "SGVsbG8sIHdvcmxkIQ"  // *see note
Base64Url::decode("SGVsbG8sIHdvcmxkIQ") => "Hello, world!"

*Note: The Base64 padding characters (=) are removed from the encoded string, but are reconstituted on decode if needed.