mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-01-06 00:17:54 -05:00
* Create a Base64 URL-Safe encoding and decoding helper * Rename web_helper to url_helper --------- Co-authored-by: El_Coloso <diegoramosp@gmail.com>
31 lines
702 B
PHP
31 lines
702 B
PHP
<?php
|
|
|
|
if (!function_exists('base64url_encode')) {
|
|
/**
|
|
* Encode data to Base64 URL-safe string.
|
|
*
|
|
* @param string $data
|
|
* @return string
|
|
*/
|
|
function base64url_encode($data)
|
|
{
|
|
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('base64url_decode')) {
|
|
/**
|
|
* Decode Base64 URL-safe string to original data.
|
|
*
|
|
* @param string $data
|
|
* @return string|false
|
|
*/
|
|
function base64url_decode($data)
|
|
{
|
|
$remainder = strlen($data) % 4;
|
|
if ($remainder) {
|
|
$data .= str_repeat('=', 4 - $remainder);
|
|
}
|
|
return base64_decode(strtr($data, '-_', '+/'));
|
|
}
|
|
} |