You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
949 B
PHP

<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2016 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
/**
* Encode and decode data into Base64 Url Safe.
*/
abstract class Base64Url
{
/**
* @param string $data The data to encode
* @param bool $use_padding If true, the "=" padding at end of the encoded value are kept, else it is removed
*
* @return string The data encoded
*/
public static function encode($data, $use_padding = false)
{
$encoded = strtr(base64_encode($data), '+/', '-_');
return true === $use_padding ? $encoded : rtrim($encoded, '=');
}
/**
* @param string $data The data to decode
*
* @return string The data decoded
*/
public static function decode($data)
{
return base64_decode(strtr($data, '-_', '+/'));
}
}