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


Java JsonWebEncryption.setAlgorithmHeaderValue方法代码示例

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


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

示例1: createJWT

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Encrypt the otp to be send via mail
 */
@Override
public String createJWT(String userid, long ttlMillis) {
  Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
  JsonWebEncryption jwe = new JsonWebEncryption();
  jwe.setKey(key);
  jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
  jwe.setEncryptionMethodHeaderParameter(
      ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
  jwe.setPayload(userid + "&&" + ttlMillis);
  try {
    return jwe.getCompactSerialization();
  } catch (JoseException e) {
    xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:20,代码来源:AuthenticationServiceImpl.java

示例2: encryptIdToken

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private String encryptIdToken(final OidcRegisteredService svc, final JsonWebSignature jws, final String innerJwt) throws Exception {
    LOGGER.debug("Service [{}] is set to encrypt id tokens", svc);
    final JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(svc.getIdTokenEncryptionAlg());
    jwe.setEncryptionMethodHeaderParameter(svc.getIdTokenEncryptionEncoding());

    final Optional<RsaJsonWebKey> jwks = this.serviceJsonWebKeystoreCache.get(svc);
    if (!jwks.isPresent()) {
        throw new IllegalArgumentException("Service " + svc.getServiceId()
                + " with client id " + svc.getClientId()
                + " is configured to encrypt id tokens, yet no JSON web key is available");
    }
    final RsaJsonWebKey jsonWebKey = jwks.get();
    LOGGER.debug("Found JSON web key to encrypt the id token: [{}]", jsonWebKey);
    if (jsonWebKey.getPublicKey() == null) {
        throw new IllegalArgumentException("JSON web key used to sign the id token has no associated public key");
    }

    jwe.setKey(jsonWebKey.getPublicKey());
    jwe.setKeyIdHeaderValue(jws.getKeyIdHeaderValue());
    jwe.setContentTypeHeaderValue("JWT");
    jwe.setPayload(innerJwt);
    return jwe.getCompactSerialization();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:OidcIdTokenSigningAndEncryptionService.java

示例3: encryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Encrypt the value based on the seed array whose length was given during afterPropertiesSet,
 * and the key and content encryption ids.
 *
 * @param value the value
 * @return the encoded value
 */
private String encryptValue(final Serializable value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setPayload(serializeValue(value));
        jwe.enableDefaultCompression();
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
        jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
        jwe.setKey(this.secretKeyEncryptionKey);
        LOGGER.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
        return jwe.getCompactSerialization();
    } catch (final Exception e) {
        throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. "
                + e.getMessage(), e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:23,代码来源:BaseStringCipherExecutor.java

示例4: decryptJWT

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Decrypt the otp received via mail
 */
@Override
public String decryptJWT(String token) {
  JsonWebEncryption jwe = new JsonWebEncryption();
  Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
  jwe.setKey(key);
  jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
  jwe.setEncryptionMethodHeaderParameter(
      ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
  try {
    jwe.setCompactSerialization(token);
    return jwe.getPayload();
  } catch (JoseException e) {
    xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
  }
  jwe.setKey(key);
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:AuthenticationServiceImpl.java

示例5: littleJweRoundTrip

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private void littleJweRoundTrip(String alg, String enc, String b64uKey) throws Exception
{
    byte[] raw = Base64Url.decode(b64uKey);
    Key key = new FakeHsmNonExtractableSecretKeySpec(raw, "AES");
    JwtClaims claims = new JwtClaims();
    claims.setExpirationTimeMinutesInTheFuture(5);
    claims.setSubject("subject");
    claims.setIssuer("issuer");
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setPayload(claims.toJson());
    jwe.setAlgorithmHeaderValue(alg);
    jwe.setEncryptionMethodHeaderParameter(enc);
    jwe.setKey(key);

    String jwt = jwe.getCompactSerialization();
    JwtConsumerBuilder jwtConsumerBuilder = new JwtConsumerBuilder();
    jwtConsumerBuilder.setAllowedClockSkewInSeconds(60);
    jwtConsumerBuilder.setRequireSubject();
    jwtConsumerBuilder.setExpectedIssuer("issuer");
    jwtConsumerBuilder.setDecryptionKey(key);
    jwtConsumerBuilder.setDisableRequireSignature();
    JwtConsumer jwtConsumer = jwtConsumerBuilder.build();
    JwtClaims processedClaims = jwtConsumer.processToClaims(jwt);
    Assert.assertThat(processedClaims.getSubject(), equalTo("subject"));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:26,代码来源:JwtConsumerTest.java

示例6: encrypt

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Override public String encrypt(String data, PublicKey publicKey, String keyId, String contentType) throws JWEFailure {
    String encrypted;
    JsonWebEncryption jwe = new JsonWebEncryption();
    try {
        jwe.setKey(publicKey);
        jwe.setPlaintext(data);
        jwe.setKeyIdHeaderValue(keyId);
        jwe.setContentTypeHeaderValue(contentType);
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.RSA_OAEP_256);
        jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
        encrypted = jwe.getCompactSerialization();
    } catch (JoseException e) {
        throw new JWEFailure("An error occurred attempting to encrypt a JWE", e);
    }
    return encrypted;
}
 
开发者ID:iovation,项目名称:launchkey-java,代码行数:17,代码来源:Jose4jJWEService.java

示例7: encryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Encrypt the value based on the seed array whose length was given during afterPropertiesSet,
 * and the key and content encryption ids.
 *
 * @param value the value
 * @return the encoded value
 */
private String encryptValue(@NotNull final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setPayload(value);
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
        jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
        jwe.setKey(this.secretKeyEncryptionKey);
        logger.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
        return jwe.getCompactSerialization();
    } catch (final Exception e) {
        throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. "
                + e.getMessage(), e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:BaseStringCipherExecutor.java

示例8: encryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Encrypt the value based on the seed array whose length was given during init,
 * and the key and content encryption ids.
 *
 * @param value the value
 * @return the encoded value
 */
private String encryptValue(@NotNull final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setPayload(value);
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
        jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
        jwe.setKey(this.secretKeyEncryptionKey);
        logger.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
        return jwe.getCompactSerialization();
    } catch (final Exception e) {
        throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. "
                + e.getMessage(), e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:DefaultCipherExecutor.java

示例9: aesEncryptDecrypt128

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Test
public void aesEncryptDecrypt128() throws Exception {

    String keyText = "iue98623diDEs096";
    String data = "I am marico";
    Key key = new AesKey(keyText.getBytes());

    //加密
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
    jwe.setKey(key);
    jwe.setPayload(data);

    String idToken = jwe.getCompactSerialization();
    assertNotNull(idToken);
    System.out.println(data + " idToken: " + idToken);

    //解密
    JsonWebEncryption jwe2 = new JsonWebEncryption();
    jwe2.setKey(key);
    jwe2.setCompactSerialization(idToken);

    final String payload = jwe2.getPayload();
    assertNotNull(payload);
    assertEquals(payload, data);

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:29,代码来源:Jose4JTest.java

示例10: aesEncryptDecrypt256

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@Test
public void aesEncryptDecrypt256() throws Exception {

    String keyText = "[email protected](*JKse09";
    String data = "I am marico";
    Key key = new AesKey(keyText.getBytes());

    //加密
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A256KW);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
    jwe.setKey(key);
    jwe.setPayload(data);

    String idToken = jwe.getCompactSerialization();
    assertNotNull(idToken);
    System.out.println(data + " idToken: " + idToken);

    //解密
    JsonWebEncryption jwe2 = new JsonWebEncryption();
    jwe2.setKey(key);
    jwe2.setCompactSerialization(idToken);

    final String payload = jwe2.getPayload();
    assertNotNull(payload);
    assertEquals(payload, data);

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:29,代码来源:Jose4JTest.java

示例11: jweEncrypt

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private String jweEncrypt(String payload, boolean isJWT, Key key, String keyAlgo, String jweAlgo) {
	try {
		JsonWebEncryption jwe = new JsonWebEncryption();
		jwe.setAlgorithmHeaderValue(ALGORITHMS.get(keyAlgo));
		jwe.setEncryptionMethodHeaderParameter(ALGORITHMS.get(jweAlgo));
		jwe.setKey(key);
		if (isJWT) jwe.setContentTypeHeaderValue("JWT");
		jwe.setPayload(payload);
		return jwe.getCompactSerialization();
	} catch (Exception e) {
		fail();
		return null;
	}
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:15,代码来源:JWTValidatorTest.java

示例12: jweEncrypt

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private static String jweEncrypt(Key key, String payload, boolean isPayloadJWT) throws Exception {
	JsonWebEncryption jwe = new JsonWebEncryption();
	jwe.setAlgorithmHeaderValue(
		KeyManagementAlgorithmIdentifiers.RSA_OAEP);
	jwe.setEncryptionMethodHeaderParameter(
		ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
	jwe.setKey(key);
	if (isPayloadJWT) jwe.setContentTypeHeaderValue("JWT");
	jwe.setPayload(payload);
	return jwe.getCompactSerialization();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:12,代码来源:JWTUtil.java

示例13: jweEncrypt

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
private String jweEncrypt(String payload, boolean isPayloadJWT) throws Exception {
	JsonWebEncryption jwe = new JsonWebEncryption();
	jwe.setAlgorithmHeaderValue(
		ALGORITHMS.get(this.jweKeyAlgo));
	jwe.setEncryptionMethodHeaderParameter(
		ALGORITHMS.get(this.jweAlgo));
	jwe.setKey(this.getJWEKey(this.jweKey, this.jweKeyAlgo));
	if (isPayloadJWT) jwe.setContentTypeHeaderValue("JWT");
	jwe.setPayload(payload);
	return jwe.getCompactSerialization();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:12,代码来源:JWTGenerator.java

示例14: encryptValue

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
/**
 * Encrypt the value based on the seed array whose length was given during init,
 * and the key and content encryption ids.
 *
 * @param value the value
 * @return the encoded value
 */
private String encryptValue(@NotNull final String value) {
    try {
        final JsonWebEncryption jwe = new JsonWebEncryption();
        jwe.setPayload(value);
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
        jwe.setEncryptionMethodHeaderParameter(this.contentEncryptionAlgorithmIdentifier);
        jwe.setKey(this.secretKeyEncryptionKey);
        LOGGER.debug("Encrypting via [{}]", this.contentEncryptionAlgorithmIdentifier);
        return jwe.getCompactSerialization();
    } catch (final Exception e) {
        throw new RuntimeException("Ensure that you have installed JCE Unlimited Strength Jurisdiction Policy Files. " + e.getMessage(), e);
    }
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:21,代码来源:DefaultCipherExecutor.java

示例15: create

import org.jose4j.jwe.JsonWebEncryption; //导入方法依赖的package包/类
@NotNull
@Override
public JsonWebEncryption create() {
  final JsonWebEncryption jwe = new JsonWebEncryption();
  jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
  jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
  jwe.setKey(key);
  return jwe;
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:10,代码来源:EncryptionFactoryAes.java


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