You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
806 B
36 lines
806 B
3 months ago
|
<?php
|
||
|
|
||
|
namespace app\utility;
|
||
|
|
||
|
|
||
|
class Base64Utility
|
||
|
{
|
||
|
/**
|
||
|
* URL base64 decoding
|
||
|
* '-' -> '+'
|
||
|
* '_' -> '/'
|
||
|
* The remainder of the string length %4, supplemented with '='
|
||
|
* @param base64 $string
|
||
|
*/
|
||
|
public static function Decode($string) {
|
||
|
$data = str_replace(array('-','_'),array('+','/'),$string);
|
||
|
$mod4 = strlen($data) % 4;
|
||
|
if ($mod4) {
|
||
|
$data .= substr('====', $mod4);
|
||
|
}
|
||
|
return base64_decode($data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* URL base64 encoding
|
||
|
* '+' -> '-'
|
||
|
* '/' -> '_'
|
||
|
* '=' -> ''
|
||
|
* @param raw $string
|
||
|
*/
|
||
|
public static function Encode($string) {
|
||
|
$data = base64_encode($string);
|
||
|
$data = str_replace(array('+','/','='),array('-','_',''),$data);
|
||
|
return $data;
|
||
|
}
|
||
|
}
|