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


Java KeyManagementAlgorithmIdentifiers类代码示例

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


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

示例1: createJWT

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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: encryptValue

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例3: decryptJWT

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例4: testNpeWithNonExtractableKeyDataDirect

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
public void testNpeWithNonExtractableKeyDataDirect() throws Exception
{
    littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256, "j-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-c");
    littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, ContentEncryptionAlgorithmIdentifiers.AES_192_CBC_HMAC_SHA_384, "X--mSrs-JGaf0ulQQFSoJGH0vjrfe_c1X--mSrs-JGaf0ulQQFSoJGH0vjrfe_c1");
    littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512, "j-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-cj-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-c");

    JceProviderTestSupport jceProviderTestSupport = new JceProviderTestSupport();
    jceProviderTestSupport.setEncryptionAlgsNeeded(AES_128_GCM, AES_192_GCM, AES_256_GCM);

    jceProviderTestSupport.runWithBouncyCastleProviderIfNeeded(
        new JceProviderTestSupport.RunnableTest()
        {
            @Override
            public void runTest() throws Exception
            {
                littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, AES_128_GCM, "mmp7iLc1cB7cQrEtqyb9c1");
                littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, AES_192_GCM, "X--mSrs-JGaf0ulQQFSoJGH0vjrfe_c1");
                littleJweRoundTrip(KeyManagementAlgorithmIdentifiers.DIRECT, AES_256_GCM, "j-DJVQ9ftUV-muUT_-yjP6dB9kuypGeT6lEGpCKOi-c");
            }
        }
    );
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:23,代码来源:JwtConsumerTest.java

示例5: jwe1

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
@Test
public void jwe1() throws JoseException
{
    String cs = "eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoiOWVyIn0." +
            "." +
            "XAog2l7TP5-0mIPYjT2ZYg." +
            "Zf6vQZhxeAfzk2AyuXsKJSo1R8aluPDvK7a6N7wvSmuIUczDhUtJFmNdXC3d4rPa." +
            "XBTguLfGeGKu6YsQVnes2w";
    JsonWebStructure jwx = JsonWebStructure.fromCompactSerialization(cs);
    jwx.setKey(oct256bitJwk.getKey());
    Assert.assertTrue(cs + " should give a JWE " + jwx, jwx instanceof JsonWebEncryption);
    Assert.assertEquals(KeyManagementAlgorithmIdentifiers.DIRECT, jwx.getAlgorithmHeaderValue());
    Assert.assertEquals(oct256bitJwk.getKeyId(), jwx.getKeyIdHeaderValue());
    String payload = jwx.getPayload();
    Assert.assertEquals(YOU_LL_GET_NOTHING_AND_LIKE_IT, payload);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:17,代码来源:JsonWebStructureTest.java

示例6: jwe2

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
@Test
public void jwe2() throws JoseException
{
    String cs = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoiOWVyIn0." +
            "RAqGCBMFk7O-B-glFckcFmxUr8BTTXuZk-bXAdRZxpk5Vgs_1yoUQw." +
            "hyl68_ADlK4VRDYiQMQS6w." +
            "xk--JKIVF4Xjxc0gRGPL30s4PSNtj685WYqXbjyItG0uSffD4ajGXdz4BO8i0sbM." +
            "WXaAVpBgftXyO1HkkRvgQQ";
    JsonWebStructure jwx = JsonWebStructure.fromCompactSerialization(cs);
    jwx.setKey(oct256bitJwk.getKey());
    Assert.assertTrue(cs + " should give a JWE " + jwx, jwx instanceof JsonWebEncryption);
    Assert.assertEquals(KeyManagementAlgorithmIdentifiers.A256KW, jwx.getAlgorithmHeaderValue());
    Assert.assertEquals(oct256bitJwk.getKeyId(), jwx.getKeyIdHeaderValue());
    String payload = jwx.getPayload();
    Assert.assertEquals(YOU_LL_GET_NOTHING_AND_LIKE_IT, payload);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:17,代码来源:JsonWebStructureTest.java

示例7: encrypt

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例8: encryptValue

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例9: encryptValue

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例10: aesEncryptDecrypt128

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例11: aesEncryptDecrypt256

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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

示例12: jweEncrypt

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的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: jweDecrypt

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
private static String jweDecrypt(Key key, String jwt) throws Exception {
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmConstraints(
    	new AlgorithmConstraints(
    		ConstraintType.WHITELIST, 
    		KeyManagementAlgorithmIdentifiers.RSA_OAEP));
    jwe.setContentEncryptionAlgorithmConstraints(
    	new AlgorithmConstraints(
    		ConstraintType.WHITELIST, 
    		ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512));
    jwe.setCompactSerialization(jwt);
    jwe.setKey(key);
    return jwe.getPlaintextString();
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:15,代码来源:JWTUtil.java

示例14: jwtProcess

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
private static String jwtProcess(Key jweKey, Key jwsKey, String jwt) throws Exception {
    AlgorithmConstraints jwsAlgConstraints = 
	    new AlgorithmConstraints(
	    	ConstraintType.WHITELIST,
	    	AlgorithmIdentifiers.HMAC_SHA512);

    AlgorithmConstraints jweAlgConstraints = 
	    new AlgorithmConstraints(
	    	ConstraintType.WHITELIST,
	    	KeyManagementAlgorithmIdentifiers.RSA_OAEP);

    AlgorithmConstraints jweEncConstraints = 
    	new AlgorithmConstraints(
    		ConstraintType.WHITELIST,
            ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);

    JwtConsumer jwtConsumer = 
    	new JwtConsumerBuilder()
            .setRequireExpirationTime()
            .setMaxFutureValidityInMinutes(300)
            .setRequireSubject()
            .setExpectedIssuer("issue-idp-1")
            .setExpectedAudience("aud-1", "aud-2")
            .setDecryptionKey(jweKey)
            .setVerificationKey(jwsKey)
            .setRelaxVerificationKeyValidation()
            .setJwsAlgorithmConstraints(jwsAlgConstraints)
            .setJweAlgorithmConstraints(jweAlgConstraints)
            .setJweContentEncryptionAlgorithmConstraints(jweEncConstraints)
            .build();

    try {
        return jwtConsumer.processToClaims(jwt).toJson();
    } catch (InvalidJwtException e) {
        System.out.println("Invalid JWT! " + e);
        return null;
    }
}
 
开发者ID:gahana,项目名称:edge-jwt-sample,代码行数:39,代码来源:JWTUtil.java

示例15: testParseExampleSymmetricKeys

import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers; //导入依赖的package包/类
public void testParseExampleSymmetricKeys() throws JoseException
{
    // from https://tools.ietf.org/html/draft-ietf-jose-json-web-key Appendix A.3
    String jwkJson = "{\"keys\":\n" +
            "       [\n" +
            "         {\"kty\":\"oct\",\n" +
            "          \"alg\":\"A128KW\",\n" +
            "          \"k\":\"GawgguFyGrWKav7AX4VKUg\"},\n" +
            "\n" +
            "         {\"kty\":\"oct\",\n" +
            "          \"k\":\"AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75\n" +
            "     aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow\",\n" +
            "          \"kid\":\"HMAC key used in JWS A.1 example\"}\n" +
            "       ]\n" +
            "     }\n";

    JsonWebKeySet jwkSet = new JsonWebKeySet(jwkJson);
    Collection<JsonWebKey> jwks = jwkSet.getJsonWebKeys();

    assertEquals(2, jwks.size());

    Iterator<JsonWebKey> iterator = jwks.iterator();
    assertTrue(iterator.next() instanceof OctetSequenceJsonWebKey);
    assertTrue(iterator.next() instanceof OctetSequenceJsonWebKey);
    assertFalse(iterator.hasNext());

    JsonWebKey jwk2 = jwkSet.findJsonWebKey("HMAC key used in JWS A.1 example", null, null, null);
    Key key2 = jwk2.getKey();
    assertNotNull(key2);
    assertEquals(64, key2.getEncoded().length);

    JsonWebKey jwk1 = jwkSet.findJsonWebKey(null, null, null, KeyManagementAlgorithmIdentifiers.A128KW);
    Key key1 = jwk1.getKey();
    assertNotNull(key1);
    assertEquals(16, key1.getEncoded().length);

}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:38,代码来源:JsonWebKeySetTest.java


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