当前位置: 首页>>代码示例>>Java>>正文


Java JsonWebSignature.setHeader方法代码示例

本文整理汇总了Java中org.jose4j.jws.JsonWebSignature.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWebSignature.setHeader方法的具体用法?Java JsonWebSignature.setHeader怎么用?Java JsonWebSignature.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jose4j.jws.JsonWebSignature的用法示例。


在下文中一共展示了JsonWebSignature.setHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildRequestToken

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private String buildRequestToken(JSONObject requestBody) {
	
	JSONObject requestHeader = buildRequestHeader();
	
	JSONObject payload = new JSONObject();
	payload.put("reqHeader", requestHeader);
	payload.put("reqBody", requestBody);
	
	JsonWebSignature jws = new JsonWebSignature();

	jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
	jws.setHeader("org_alias", this.orgAlias);
	jws.setHeader("token", this.token);
	
	jws.setPayload(payload.toJSONString());
	
    // Set the verification key
    HmacKey key = new HmacKey(Base64.decode(this.useBase64Key));
    jws.setKey(key);
	
	String jwsCompactSerialization = null;
	try {
		jwsCompactSerialization = jws.getCompactSerialization();
	} catch (JoseException e) {
		e.printStackTrace();
	}
	
	this.requestToken = jwsCompactSerialization;
			
	return jwsCompactSerialization;
}
 
开发者ID:pingidentity,项目名称:pingid-api-playground,代码行数:33,代码来源:Operation.java

示例2: constructJWTAssertion

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
private String constructJWTAssertion(NumericDate now) {
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(this.getClientID());
    claims.setAudience(JWT_AUDIENCE);
    if (now == null) {
        claims.setExpirationTimeMinutesInTheFuture(1.0f);
    } else {
        now.addSeconds(60L);
        claims.setExpirationTime(now);
    }
    claims.setSubject(this.entityID);
    claims.setClaim("box_sub_type", this.entityType.toString());
    claims.setGeneratedJwtId(64);

    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(claims.toJson());
    jws.setKey(this.decryptPrivateKey());
    jws.setAlgorithmHeaderValue(this.getAlgorithmIdentifier());
    jws.setHeader("typ", "JWT");
    if ((this.publicKeyID != null) && !this.publicKeyID.isEmpty()) {
        jws.setHeader("kid", this.publicKeyID);
    }

    String assertion;

    try {
        assertion = jws.getCompactSerialization();
    } catch (JoseException e) {
        throw new BoxAPIException("Error serializing JSON Web Token assertion.", e);
    }

    return assertion;
}
 
开发者ID:box,项目名称:box-java-sdk,代码行数:34,代码来源:BoxDeveloperEditionAPIConnection.java

示例3: serializeAndSign

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public static String serializeAndSign(Map<String, Object> claims, String key) {
    JsonWebSignature jws = new JsonWebSignature();
    jws.setPayload(new Gson().toJson(claims));
    jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
    jws.setHeader("typ", "JWT");
    jws.setKey(new HmacKey(Arrays.copyOf(key.getBytes(), 32)));

    try {
        return jws.getCompactSerialization();
    } catch (JoseException e) {
        throw new TokenException(e);
    }
}
 
开发者ID:Livefyre,项目名称:livefyre-java-utils,代码行数:14,代码来源:LivefyreUtil.java

示例4: createJWT

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
public static String createJWT(final String secret, final String payload) throws JoseException
{
	String token;
	JsonWebSignature sig = new JsonWebSignature();
	//sig.setKey(new HmacKey(DigestUtils.sha256(secret.getBytes(StandardCharsets.UTF_8))));
	sig.setKey(new HmacKey(secret.getBytes(StandardCharsets.UTF_8)));
	sig.setDoKeyValidation(false);
	sig.setPayload(payload);
	sig.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
	sig.setHeader(HeaderParameterNames.TYPE, "JWT");

	token = sig.getCompactSerialization();
	return token;
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:15,代码来源:JwtCreationRestServiceImpl.java

示例5: sendAsync

import org.jose4j.jws.JsonWebSignature; //导入方法依赖的package包/类
/**
 * Send a notification, but don't wait for the response.
 *
 * @param notification
 * @return
 * @throws GeneralSecurityException
 * @throws IOException
 * @throws JoseException
 */
public Future<HttpResponse> sendAsync(Notification notification) throws GeneralSecurityException, IOException, JoseException {
    BaseEncoding base64url = BaseEncoding.base64Url();

    Encrypted encrypted = encrypt(
        notification.getPayload(),
        notification.getUserPublicKey(),
        notification.getUserAuth(),
        notification.getPadSize()
    );

    byte[] dh = Utils.savePublicKey((ECPublicKey) encrypted.getPublicKey());
    byte[] salt = encrypted.getSalt();

    HttpPost httpPost = new HttpPost(notification.getEndpoint());
    httpPost.addHeader("TTL", String.valueOf(notification.getTTL()));

    Map<String, String> headers = new HashMap<>();

    if (notification.hasPayload()) {
        headers.put("Content-Type", "application/octet-stream");
        headers.put("Content-Encoding", "aesgcm");
        headers.put("Encryption", "keyid=p256dh;salt=" + base64url.omitPadding().encode(salt));
        headers.put("Crypto-Key", "keyid=p256dh;dh=" + base64url.encode(dh));

        httpPost.setEntity(new ByteArrayEntity(encrypted.getCiphertext()));
    }

    if (notification.isGcm()) {
        if (gcmApiKey == null) {
            throw new IllegalStateException("An GCM API key is needed to send a push notification to a GCM endpoint.");
        }

        headers.put("Authorization", "key=" + gcmApiKey);
    }

    if (vapidEnabled() && !notification.isGcm()) {
        JwtClaims claims = new JwtClaims();
        claims.setAudience(notification.getOrigin());
        claims.setExpirationTimeMinutesInTheFuture(12*60);
        claims.setSubject(subject);

        JsonWebSignature jws = new JsonWebSignature();
        jws.setHeader("typ", "JWT");
        jws.setHeader("alg", "ES256");
        jws.setPayload(claims.toJson());
        jws.setKey(privateKey);
        jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.ECDSA_USING_P256_CURVE_AND_SHA256);

        headers.put("Authorization", "WebPush " + jws.getCompactSerialization());

        byte[] pk = Utils.savePublicKey((ECPublicKey) publicKey);

        if (headers.containsKey("Crypto-Key")) {
            headers.put("Crypto-Key", headers.get("Crypto-Key") + ";p256ecdsa=" + base64url.omitPadding().encode(pk));
        } else {
            headers.put("Crypto-Key", "p256ecdsa=" + base64url.encode(pk));
        }
    }

    for (Map.Entry<String, String> entry : headers.entrySet()) {
        httpPost.addHeader(new BasicHeader(entry.getKey(), entry.getValue()));
    }

    final CloseableHttpAsyncClient closeableHttpAsyncClient = HttpAsyncClients.createSystem();
    closeableHttpAsyncClient.start();

    return closeableHttpAsyncClient.execute(httpPost, new ClosableCallback(closeableHttpAsyncClient));
}
 
开发者ID:web-push-libs,项目名称:webpush-java,代码行数:78,代码来源:PushService.java


注:本文中的org.jose4j.jws.JsonWebSignature.setHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。