mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-10-22 11:26:12 +02:00
The tilde character is less familiar to most users and harder to type on most keyboards (compared to the hyphen and underscore characters).
35 lines
729 B
PHP
35 lines
729 B
PHP
<?php
|
|
|
|
/*
|
|
* PHP-Auth (https://github.com/delight-im/PHP-Auth)
|
|
* Copyright (c) delight.im (https://www.delight.im/)
|
|
* Licensed under the MIT License (https://opensource.org/licenses/MIT)
|
|
*/
|
|
|
|
namespace Delight\Auth;
|
|
|
|
final class Base64 {
|
|
|
|
const SPECIAL_CHARS_ORIGINAL = '+/=';
|
|
const SPECIAL_CHARS_SAFE = '_-~';
|
|
|
|
public static function encode($data, $safeChars = false) {
|
|
$result = base64_encode($data);
|
|
|
|
if ($safeChars) {
|
|
$result = strtr($result, self::SPECIAL_CHARS_ORIGINAL, self::SPECIAL_CHARS_SAFE);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function decode($data) {
|
|
$data = strtr($data, self::SPECIAL_CHARS_SAFE, self::SPECIAL_CHARS_ORIGINAL);
|
|
|
|
$result = base64_decode($data, true);
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|