mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-02-24 02:46:56 -05:00
35 lines
726 B
PHP
35 lines
726 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 false|string
|
|
*/
|
|
function base64url_decode($data)
|
|
{
|
|
$remainder = strlen($data) % 4;
|
|
if ($remainder) {
|
|
$data .= str_repeat('=', 4 - $remainder);
|
|
}
|
|
|
|
return base64_decode(strtr($data, '-_', '+/'), true);
|
|
}
|
|
}
|