本文整理汇总了Java中org.jose4j.jwk.RsaJwkGenerator.generateJwk方法的典型用法代码示例。如果您正苦于以下问题:Java RsaJwkGenerator.generateJwk方法的具体用法?Java RsaJwkGenerator.generateJwk怎么用?Java RsaJwkGenerator.generateJwk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.jwk.RsaJwkGenerator
的用法示例。
在下文中一共展示了RsaJwkGenerator.generateJwk方法的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);
}
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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");
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
}
示例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");
}
示例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()));
}
示例14: beforeClass
import org.jose4j.jwk.RsaJwkGenerator; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws JoseException {
signatureKeyPair = RsaJwkGenerator.generateJwk(2048);
signatureKeyPair.setKeyId(TOKEN_ISSUER + "-signkey");
}
示例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);
}