mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-05-04 07:16:27 +02:00
encode token to prevent bad url
This commit is contained in:
parent
01f836108d
commit
aaa0fe5701
3 changed files with 31 additions and 3 deletions
|
@ -463,4 +463,28 @@ use BenMorel\GsmCharsetConverter\Converter;
|
|||
$converter = new Converter();
|
||||
return $converter->cleanUpUtf8String($text, true, '?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode some data into the URL version of Base64 encoding
|
||||
*
|
||||
* @param string $data Input data
|
||||
* @return string A Base64 (URL-safe) encoded string
|
||||
*/
|
||||
public static function url_base64_encode(string $data): string
|
||||
{
|
||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a URL-safe Base64 encoded string
|
||||
*
|
||||
* @param string $data Encoded data
|
||||
* @return string Decoded original data
|
||||
*/
|
||||
public static function url_base64_decode(string $data): string
|
||||
{
|
||||
$replaced = strtr($data, '-_', '+/');
|
||||
$padded = str_pad($replaced, mb_strlen($replaced) % 4 === 0 ? mb_strlen($replaced) : mb_strlen($replaced) + 4 - mb_strlen($replaced) % 4, '=', STR_PAD_RIGHT);
|
||||
return base64_decode($padded);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue