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


Java RsaJwkGenerator类代码示例

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


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

示例1: generate

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Generate.
 */
@PostConstruct
public void generate() {
    try {
        final File file = oidcProperties.getJwksFile().getFile();
        if (!file.exists()) {
            final RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
            final JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(rsaJsonWebKey);
            final String data = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
            FileUtils.write(file, data, StandardCharsets.UTF_8);
            LOGGER.debug("Generated JSON web keystore at [{}]", file);
        } else {
            LOGGER.debug("Located JSON web keystore at [{}]", file);
        }
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:OidcJsonWebKeystoreGeneratorService.java

示例2: testSuccessClientGeneratedRSAKeys

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
@Test
public void testSuccessClientGeneratedRSAKeys() throws Exception {

	JsonWebKey popKey = RsaJwkGenerator.generateJwk(2048);
	popKey.setKeyId("testkid");
	
	TokenRequest req = new TokenRequest();
	req.setGrantType("client_credentials");
	req.setAud(config.getResourceServers().get(0).getAud());
	req.setClientID(config.getClients().get(0).getClient_id());
	req.setClientSecret(config.getClients().get(0).getClient_secret());
	req.setScopes(config.getResourceServers().get(0).getScopes());
	req.setKey(popKey);

	Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());		

	Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
	
	TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);

	TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
 
开发者ID:erwah,项目名称:acetest,代码行数:23,代码来源:TokenResourceTest.java

示例3: generateJWT

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
public void generateJWT() throws Exception {
    // Generate a new RSA key pair wrapped in a JWK
    PublicJsonWebKey rsaJwk = RsaJwkGenerator.generateJwk(2048);

    // or an EC key, if you prefer
    PublicJsonWebKey ecJwk = EcJwkGenerator.generateJwk(EllipticCurves.P256);

    // A JSON string with only the public key info
    String publicKeyJwkString = rsaJwk.toJson(JsonWebKey.OutputControlLevel.PUBLIC_ONLY);
    System.out.println(publicKeyJwkString);

    // A JSON string with both the public and private key info
    String keyPairJwkString = rsaJwk.toJson(JsonWebKey.OutputControlLevel.INCLUDE_PRIVATE);
    System.out.println(keyPairJwkString);

    // parse and convert into PublicJsonWebKey/JsonWebKey objects
    PublicJsonWebKey parsedPublicKeyJwk = PublicJsonWebKey.Factory.newPublicJwk(publicKeyJwkString);
    PublicJsonWebKey parsedKeyPairJwk = PublicJsonWebKey.Factory.newPublicJwk(keyPairJwkString);

    // the private key can be used to sign (JWS) or decrypt (JWE)
    PrivateKey privateKey = parsedKeyPairJwk.getPrivateKey();

    // the public key can be used to verify (JWS) or encrypt (JWE)
    PublicKey publicKey = parsedPublicKeyJwk.getPublicKey();
}
 
开发者ID:CyborTronik,项目名称:fluent-registry,代码行数:26,代码来源:JwtGeneratorTest.java

示例4: buildNewRsaKey

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
private RsaJsonWebKey buildNewRsaKey() {

        try {
            final RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
            rsaJsonWebKey.setKeyId(tokenGenerator.newToken());
            rsaJsonWebKey.setAlgorithm(AlgorithmIdentifiers.RSA_USING_SHA512);
            rsaJsonWebKey.setUse("sig");
            return rsaJsonWebKey;
        } catch (final JoseException e) {
            throw new InternalServerErrorException(e);
        }
    }
 
开发者ID:trajano,项目名称:app-ms,代码行数:13,代码来源:CachedDataProvider.java

示例5: generateRsaJsonWebKey

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Generate a {@link RsaJsonWebKey}.
 */
public static RsaJsonWebKey generateRsaJsonWebKey(String keyId) {
  try {
    RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);
    rsaJsonWebKey.setAlgorithm(AlgorithmIdentifiers.RSA_USING_SHA256);
    rsaJsonWebKey.setKeyId(keyId);
    return rsaJsonWebKey;
  } catch (JoseException exception) {
    throw new RuntimeException("failed to generate RSA Json web key", exception);
  }
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:14,代码来源:TestUtils.java

示例6: setUp

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Initialize the JSON web keys before each test.
 */
@Before
public void setUp() throws JoseException {
  this.rsaJwk1 = RsaJwkGenerator.generateJwk(BITS_OF_KEY);
  this.rsaJwk1.setKeyId("rsa-jwk-1");
  this.rsaJwk2 = RsaJwkGenerator.generateJwk(BITS_OF_KEY);
  this.rsaJwk2.setKeyId("rsa-jwk-2");
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:11,代码来源:DefaultAuthTokenVerifierTest.java

示例7: testSupplyJwks

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
@Test
public void testSupplyJwks() throws JoseException {
  RsaJsonWebKey rsaJwk = RsaJwkGenerator.generateJwk(2048);
  JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(rsaJwk);
  HttpTransport httpTransport = new TestingHttpTransport(jsonWebKeySet.toJson(), null);
  DefaultJwksSupplier jwksSupplier =
      new DefaultJwksSupplier(httpTransport.createRequestFactory(), keyUriSupplier);
  List<JsonWebKey> jsonWebKeys = jwksSupplier.supply(ISSUER).getJsonWebKeys();
  JsonWebKey jsonWebKey = Iterables.getOnlyElement(jsonWebKeys);

  assertKeysEqual(rsaJwk.getKey(), jsonWebKey.getKey());
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:13,代码来源:DefaultJwksSupplierTest.java

示例8: produce

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * 
 * not an ideal implementation since does not implement double-lock synchronization check
 */
public static RsaJsonWebKey produce(){
	if(theOne == null){
		try {
			theOne = RsaJwkGenerator.generateJwk(2048);
		} catch (JoseException ex) {
			Logger.getLogger(RsaKeyProducer.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	System.out.println("RSA Key setup... "+ theOne.hashCode());
	return theOne;
}
 
开发者ID:danielemaddaluno,项目名称:jaxrs-jws-jwt-web,代码行数:17,代码来源:RsaKeyProducer.java

示例9: createRsaJsonKey

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
private RsaJsonWebKey createRsaJsonKey() throws Exception {
	// Generate an RSA key pair, which will be used for signing and verification of the JWT, wrapped in a JWK
	RsaJsonWebKey rsaJsonWebKey = RsaJwkGenerator.generateJwk(2048);

	// Give the JWK a Key ID (kid), which is just the polite thing to do
	rsaJsonWebKey.setKeyId("eetlite.cz");
	return rsaJsonWebKey;
}
 
开发者ID:eetlite,项目名称:eet.osslite.cz,代码行数:9,代码来源:JwtRest.java

示例10: getKey

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Get the RSA key pair.
 * The method will create a pair, if non exists, i.e. the first call of this method.
 * If no pair can be created, it will shutdown the VM because this would mean a hugh security risk.
 *
 * @return The RSA key pair
 */
public static RsaJsonWebKey getKey() {
    if (rsaJsonWebKey == null) {
        try {
            rsaJsonWebKey = RsaJwkGenerator.generateJwk(JWK_STRENGTH_IN_BITS);
        } catch (JoseException e) {
            e.printStackTrace();
            System.exit(0);
        }
    }

    return rsaJsonWebKey;
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:20,代码来源:JWTHelper.java

示例11: validateForgedAuthToken

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Validation of an authentication token signed with the wrong key (or some
 * other party) should not be validated.
 */
@Test
public void validateForgedAuthToken() throws Exception {
    DateTime expirationTime = UtcTime.now().plusMinutes(10);
    RsaJsonWebKey wrongKeyPair = RsaJwkGenerator.generateJwk(2048);
    String forgedToken = signToken(TOKEN_ISSUER, wrongKeyPair, expirationTime);
    String authzHeader = "Bearer " + forgedToken;
    try {
        validator.validate(authzHeader);
        fail("validation should have failed");
    } catch (AuthTokenValidationException e) {
        assertValidationException(e, "failed to validate Authorization token", "signature is invalid");
    }
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:18,代码来源:TestAuthTokenHeaderValidator.java

示例12: beforeTestMethod

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
@Before
public void beforeTestMethod() throws Exception {
    // test methods start need to start their own server
    this.server = null;
    FrozenTime.setFixed(UtcTime.parse("2015-01-01T12:00:00.000Z"));
    this.signatureKeyPair = RsaJwkGenerator.generateJwk(2048);
    this.signatureKeyPair.setKeyId(TOKEN_ISSUER + "-signkey");
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:9,代码来源:TestAuthTokenRequestFilter.java

示例13: accessProtectedResourceWithForgedAuthToken

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Verify that a protected resource cannot be accessed when an
 * authentication token signed with the wrong key (or some other party) is
 * used.
 */
@Test
public void accessProtectedResourceWithForgedAuthToken() throws Exception {
    startServer(new AsymmetricKeyAuthTokenValidator(this.signatureKeyPair).withExpectedIssuer(TOKEN_ISSUER));

    DateTime expirationTime = UtcTime.now().plusMinutes(10);
    RsaJsonWebKey wrongKeyPair = RsaJwkGenerator.generateJwk(2048);
    String forgedToken = signToken(TOKEN_ISSUER, wrongKeyPair, expirationTime);
    Response response = getWithToken("/api/protected", forgedToken);
    assertThat(response.getStatus(), is(Status.UNAUTHORIZED.getStatusCode()));
    assertThat(response.readEntity(ErrorType.class), is(error("failed to validate Authorization token")));
    // verify that error header is present
    assertThat(response.getHeaderString("WWW-Authenticate"), is(notNullValue()));
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:19,代码来源:TestAuthTokenRequestFilter.java

示例14: beforeClass

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws JoseException {
    signatureKeyPair = RsaJwkGenerator.generateJwk(2048);
    signatureKeyPair.setKeyId(TOKEN_ISSUER + "-signkey");
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:6,代码来源:TestAuthTokenHeaderValidator.java

示例15: generateRsaJwk

import org.jose4j.jwk.RsaJwkGenerator; //导入依赖的package包/类
/**
 * Generate a 2048 bits JSON web key.
 * @return JSON web key
 * @throws JoseException
 */
private RsaJsonWebKey generateRsaJwk() throws JoseException {

  return RsaJwkGenerator.generateJwk(2048);
}
 
开发者ID:Staffbase,项目名称:plugins-sdk-java,代码行数:10,代码来源:SSOFacadeTest.java


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