urlsafeB64Encode() публичный статический Метод

Encode a string with URL-safe Base64.
public static urlsafeB64Encode ( string $input ) : string
$input string The string you want encoded
Результат string The base64 encode of what you passed in
Пример #1
0
 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);
 }
Пример #2
0
 /**
  * @param object|array $payload PHP object or array
  * @param string       $key     The secret key
  * @param string       $algo    The signing algorithm
  *
  * @return string A JWT
  */
 public static function encode($payload, $key, $type, $algo = 'HS256')
 {
     $header = array('typ' => 'JWT', 'alg' => $algo);
     $segments = array();
     $tmp_str = implode(',', $payload);
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     if ($type) {
         $segments[] = JWT::urlsafeB64Encode_parse(JWT::jsonEncode($payload));
     } else {
         $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     }
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $algo);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
Пример #3
0
 public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null)
 {
     $header = array('typ' => 'JWT', 'alg' => $alg);
     if ($keyId !== null) {
         $header['kid'] = $keyId;
     }
     if (isset($head) && is_array($head)) {
         $header = array_merge($head, $header);
     }
     $segments = array();
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $alg);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
Пример #4
0
 /**
  * Converts and signs a PHP object or array into a JWT string.
  *
  * @param object|array $payload PHP object or array
  * @param string       $key     The secret key
  * @param string       $alg     The signing algorithm. Supported
  *                              algorithms are 'HS256', 'HS384' and 'HS512'
  * @param array        $head    An array with header elements to attach
  * @param array        $options Extra options (audience, issuer, jwtid, subject)
  *
  * @return string      A signed JWT
  * @uses jsonEncode
  * @uses urlsafeB64Encode
  */
 public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null, $options = array())
 {
     $header = array('typ' => 'JWT', 'alg' => $alg);
     if ($keyId !== null) {
         $header['kid'] = $keyId;
     }
     if (isset($head) && is_array($head)) {
         $header = array_merge($head, $header);
     }
     if (isset($options['audience']) && (is_string($options['audience']) || is_array($options['audience']))) {
         if (is_array($payload)) {
             $payload['aud'] = is_array($options['audience']) ? $options['audience'] : array($options['audience']);
         } else {
             if (is_object($payload)) {
                 $payload->aud = is_array($options['audience']) ? $options['audience'] : array($options['audience']);
             }
         }
     }
     if (isset($options['issuer']) && is_string($options['issuer'])) {
         if (is_array($payload)) {
             $payload['iss'] = $options['issuer'];
         } else {
             if (is_object($payload)) {
                 $payload->iss = $options['issuer'];
             }
         }
     }
     if (isset($options['subject']) && is_string($options['subject'])) {
         if (is_array($payload)) {
             $payload['sub'] = $options['subject'];
         } else {
             if (is_object($payload)) {
                 $payload->sub = $options['subject'];
             }
         }
     }
     if (isset($options['jwtid']) && is_string($options['jwtid'])) {
         if (is_array($payload)) {
             $payload['jti'] = $options['jwtid'];
         } else {
             if (is_object($payload)) {
                 $payload->jti = $options['jwtid'];
             }
         }
     }
     $segments = array();
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $alg);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
Пример #5
0
 public function urlSafeB64Encode($data)
 {
     return \JWT::urlsafeB64Encode($data);
 }