Encode a JWT.

@return encoded JWT
321501
public String toJwt() {
        Map<String, Object> headers = new HashMap<>();
        headers.put("typ", "JWT");
        headers.putAll(this.getHeaders());

        JwtBuilder builder =
            Jwts.builder()
                .signWith(this.algorithm, this.secretKey)
                .setHeaderParams(headers)
                .setIssuer(this.issuer)
                .setExpiration(expiration);

        if (this.getClaims() != null) {
            for (Map.Entry<String, Object> entry : this.getClaims().entrySet()) {
                builder.claim(entry.getKey(), entry.getValue());
            }
        }

        if (this.getId() != null) {
            builder.setId(this.getId());
        }

        if (this.getSubject() != null) {
            builder.setSubject(this.getSubject());
        }

        if (this.getNbf() != null) {
            builder.setNotBefore(this.getNbf());
        }

        return builder.compact();
    }
424094
public function getJWT()
    {
        // Collect all the data
        $secret      = static::getSecretKey();
        $currentTime = time();
        $request     = Yii::$app->request;
        $hostInfo    = '';

        // There is also a \yii\console\Request that doesn't have this property
        if ($request instanceof WebRequest) {
            $hostInfo = $request->hostInfo;
        }

        // Merge token with presets not to miss any params in custom
        // configuration
        $token = array_merge([
            'iss' => $hostInfo,
            'aud' => $hostInfo,
            'iat' => $currentTime,
            'nbf' => $currentTime
        ], static::getHeaderToken());

        // Set up id
        $token['jti'] = $this->getJTI();

        return JWT::encode($token, $secret, static::getAlgo());
    }
1283714
public String encode() {
    byte[] credentialsBytes = combine().getBytes(UTF_8);
    return Base64.getEncoder().encodeToString(credentialsBytes);
  }
895871
public function encode()
    {
        $mimeType = Resources::MULTIPART_MIXED_TYPE;
        $batchGuid = Utilities::getGuid();
        $batchId = sprintf('batch_%s', $batchGuid);
        $contentType1 = ['content_type' => "$mimeType"];
        $changeSetGuid = Utilities::getGuid();
        $changeSetId = sprintf('changeset_%s', $changeSetGuid);
        $contentType2 = ['content_type' => "$mimeType; boundary=$changeSetId"];
        $options = [
            'encoding' => 'binary',
            'content_type' => Resources::HTTP_TYPE,
        ];

        // Create changeset MIME part
        $changeSet = new Mail_mimePart();

        $i = 1;
        foreach ($this->_contexts as $context) {
            $context->addHeader(Resources::CONTENT_ID, $i);
            $changeSet->addSubpart((string) $context, $options);

            ++$i;
        }

        // Encode the changeset MIME part
        $changeSetEncoded = $changeSet->encode($changeSetId);

        // Create the batch MIME part
        $batch = new Mail_mimePart(Resources::EMPTY_STRING, $contentType1);

        // Add changeset encoded to batch MIME part
        $batch->addSubpart($changeSetEncoded['body'], $contentType2);

        // Encode batch MIME part
        $batchEncoded = $batch->encode($batchId);

        $this->_headers = $batchEncoded['headers'];
        $this->_body = $batchEncoded['body'];
    }
158135
public function getJwtToken()
    {
        if ($this->token && $this->token->isValid()) {
            return $this->token;
        }

        $url = $this->options['token_url'];

        $requestOptions = array_merge(
            $this->getDefaultHeaders(),
            $this->auth->getRequestOptions()
        );

        $response = $this->client->request('POST', $url, $requestOptions);
        $body = json_decode($response->getBody(), true);

        $expiresIn = isset($body[$this->options['expire_key']]) ? $body[$this->options['expire_key']] : null;

        if ($expiresIn) {
            $expiration = new \DateTime('now + ' . $expiresIn . ' seconds');
        } elseif (count($jwtParts = explode('.', $body[$this->options['token_key']])) === 3
            && is_array($payload = json_decode(base64_decode($jwtParts[1]), true))
            // https://tools.ietf.org/html/rfc7519.html#section-4.1.4
            && array_key_exists('exp', $payload)
        ) {
            // Manually process the payload part to avoid having to drag in a new library
            $expiration = new \DateTime('@' . $payload['exp']);
        } else {
            $expiration = null;
        }

        $this->token = new JwtToken($body[$this->options['token_key']], $expiration);

        return $this->token;
    }
966414
public function encode()
    {
    	foreach ($this->body as $key => $value) {
    		$result[] = $this->replaceText($value);
    	}

    	return implode('', $result);
    }
1278112
public function getToken() : string {
        if (($this->token === null) || ($this->token->isExpired())) {
            $jwtBuilder = new Builder();
            $jwtBuilder->set('iss', $this->credentialPublicKey);
            $jwtBuilder->set('sub', $this->userName);

            $this->token = $jwtBuilder
                ->sign(new Sha256(), $this->credentialPrivateKey)
                ->getToken();
        }

        return (string) $this->token;
    }
593142
public function encode() : string
    {
        $segments = [
            $this->header->encode(),
            $this->payload->encode(),
            self::base64UrlEncode($this->signature)
        ];

        return implode('.', $segments);
    }
360126
public function generateSigninInput()
    {
        $base64payload = $this->encoder->encode(json_encode($this->getPayload(), JSON_UNESCAPED_SLASHES));
        $base64header = $this->encoder->encode(json_encode($this->getHeader(), JSON_UNESCAPED_SLASHES));

        return sprintf('%s.%s', $base64header, $base64payload);
    }
1292865
protected function createToken($data)
    {
        $key = self::getJwtKey();

        $token = array(
            "iat" => time(),
            "provider" => get_class($this),
            "category" => $this->category,
            "data" => $data
        );

        $jwt = JWT::encode($token, $key);

        return $jwt;
    }
384984
public static String encode( String s )
    {
        byte[] sBytes = s.getBytes();
        sBytes = encode( sBytes );
        s = new String( sBytes );
        return s;
    }
1349255
public function jsonSerialize()
    {
        $coded = array(
            'type' => $this->getType(),
            'title' => $this->getTitle(),
            'description' => $this->getDescription(),
            'symbol' => $this->getSymbol(),
            'currency' => $this->getCurrency()
        );
        return $coded;
    }
71505
private String createAuthEncoded() {
        JsonObject ret = new JsonObject();
        putNonNull(ret, "username", username);
        putNonNull(ret, "password", password);
        putNonNull(ret, "email", email);
        putNonNull(ret, "auth", auth);
        try {
            return encodeBase64ChunkedURLSafeString(ret.toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            return encodeBase64ChunkedURLSafeString(ret.toString().getBytes());
        }
    }
529080
protected function encode($payload, $key)
	{
		if( isset($payload['exp']) ) {
			$payload['exp'] = time() + $this->minToSec($payload['exp']);
		}
		return JWT::encode($payload, $key, $this->algo);
	}
69384
protected function encodeContents()
    {
        $serverIDEncoded = StringType::write($this->serverID);

        $encodedPublicKey = base64_decode($this->getPublicKey());
        $publicKeyLength = VarInt::writeUnsignedVarInt(strlen($encodedPublicKey));

        $encodedToken = $this->getToken();
        $tokenLength = VarInt::writeUnsignedVarInt(strlen($encodedToken));

        return $serverIDEncoded->getEncoded() . $publicKeyLength->getEncoded() . $encodedPublicKey . $tokenLength->getEncoded() . $encodedToken;
    }
881261
def to_jwt(self, algorithm=None, ttl=None):
        

        if not self.secret_key:
            raise ValueError('JWT does not have a signing key configured.')

        headers = self.headers.copy()
        if algorithm:
            headers['alg'] = algorithm
        algorithm = algorithm or self.algorithm

        payload = self.payload.copy()
        if ttl:
            payload['exp'] = int(time.time()) + ttl

        return jwt_lib.encode(payload, self.secret_key, algorithm=algorithm, headers=headers)
474711
public byte[] encode() {
		char type = getAttributeType();
		byte binValue[] = new byte[HEADER_LENGTH + getDataLength()];

		// Type
		binValue[0] = (byte) (type >> 8);
		binValue[1] = (byte) (type & 0x00FF);

		// Length
		binValue[2] = (byte) (getDataLength() >> 8);
		binValue[3] = (byte) (getDataLength() & 0x00FF);

		return binValue;
	}