public static urlsafeB64Encode ( string $input ) : string | ||
$input | string | The string you want encoded |
리턴 | string | The base64 encode of what you passed in |
public static function urlsafeB64Encode($input)
{
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
public static function encode($payload, $key, $algo = 'HS256') { $header = array('typ' => 'JWT', 'alg' => $algo); $segments = array(JWT::urlsafeB64Encode(json_encode($header)), JWT::urlsafeB64Encode(json_encode($payload))); $signing_input = implode('.', $segments); $signature = JWT::sign($signing_input, $key, $algo); $segments[] = JWT::urlsafeB64Encode($signature); return implode('.', $segments); }