本文整理汇总了Java中org.jose4j.jwk.RsaJsonWebKey.getPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java RsaJsonWebKey.getPublicKey方法的具体用法?Java RsaJsonWebKey.getPublicKey怎么用?Java RsaJsonWebKey.getPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.jwk.RsaJsonWebKey
的用法示例。
在下文中一共展示了RsaJsonWebKey.getPublicKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJsonSigningWebKeyFromJwks
import org.jose4j.jwk.RsaJsonWebKey; //导入方法依赖的package包/类
private static RsaJsonWebKey getJsonSigningWebKeyFromJwks(final JsonWebKeySet jwks) {
if (jwks.getJsonWebKeys().isEmpty()) {
LOGGER.warn("No JSON web keys are available in the keystore");
return null;
}
final RsaJsonWebKey key = (RsaJsonWebKey) jwks.getJsonWebKeys().get(0);
if (StringUtils.isBlank(key.getAlgorithm())) {
LOGGER.warn("Located JSON web key [{}] has no algorithm defined", key);
}
if (StringUtils.isBlank(key.getKeyId())) {
LOGGER.warn("Located JSON web key [{}] has no key id defined", key);
}
if (key.getPublicKey() == null) {
LOGGER.warn("Located JSON web key [{}] has no public key", key);
return null;
}
return key;
}
示例2: encryptIdToken
import org.jose4j.jwk.RsaJsonWebKey; //导入方法依赖的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();
}
示例3: buildJsonWebKeySet
import org.jose4j.jwk.RsaJsonWebKey; //导入方法依赖的package包/类
private Optional<JsonWebKeySet> buildJsonWebKeySet(final OidcRegisteredService service) throws Exception {
try {
LOGGER.debug("Loading JSON web key from [{}]", service.getJwks());
final Resource resource = this.resourceLoader.getResource(service.getJwks());
final JsonWebKeySet jsonWebKeySet = buildJsonWebKeySet(resource);
if (jsonWebKeySet == null || jsonWebKeySet.getJsonWebKeys().isEmpty()) {
LOGGER.warn("No JSON web keys could be found for [{}]", service);
return Optional.empty();
}
final long badKeysCount = jsonWebKeySet.getJsonWebKeys().stream().filter(k ->
StringUtils.isBlank(k.getAlgorithm())
&& StringUtils.isBlank(k.getKeyId())
&& StringUtils.isBlank(k.getKeyType())).count();
if (badKeysCount == jsonWebKeySet.getJsonWebKeys().size()) {
LOGGER.warn("No valid JSON web keys could be found for [{}]", service);
return Optional.empty();
}
final RsaJsonWebKey webKey = getJsonSigningWebKeyFromJwks(jsonWebKeySet);
if (webKey.getPublicKey() == null) {
LOGGER.warn("JSON web key retrieved [{}] has no associated public key", webKey.getKeyId());
return Optional.empty();
}
return Optional.of(jsonWebKeySet);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return Optional.empty();
}
示例4: dtlsRPKRequest
import org.jose4j.jwk.RsaJsonWebKey; //导入方法依赖的package包/类
public static Response dtlsRPKRequest(String uri, String method, byte[] payload, int contentFormat, JsonWebKey popKey, ArrayList<PublicKey> trustedPublicKeys) throws Exception {
Request request = Utils.newRequest(method);
request.setURI(uri);
request.setPayload(payload);
request.getOptions().setContentFormat(contentFormat);
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));
PublicKey publicKey = null;
PrivateKey privateKey = null;
if(popKey.getKeyType().equalsIgnoreCase("ec")) {
EllipticCurveJsonWebKey ecPopKey = (EllipticCurveJsonWebKey) popKey;
privateKey = ecPopKey.getPrivateKey();
publicKey = ecPopKey.getPublicKey();
}
else if(popKey.getKeyType().equalsIgnoreCase("rsa")) {
RsaJsonWebKey rsaPopKey = (RsaJsonWebKey) popKey;
privateKey = rsaPopKey.getPrivateKey();
publicKey = rsaPopKey.getPublicKey();
}
// use the POP key as the requests identity
builder.setIdentity(privateKey, publicKey);
// authenticate the remote part using PSK
builder.setTrustedPublicKeysStore(trustedPublicKeys);
DTLSConnector dtlsconnector = new DTLSConnector(builder.build(), null);
NetworkConfig nc = NetworkConfig.getStandard().setInt("COAP_SECURE_PORT", 15685);
dtlsEndpoint = new CoapEndpoint(dtlsconnector, nc);
dtlsEndpoint.start();
// execute request
request.send(dtlsEndpoint);
Response response = request.waitForResponse();
return response;
}
示例5: asymmetricEcClient
import org.jose4j.jwk.RsaJsonWebKey; //导入方法依赖的package包/类
private static void asymmetricEcClient() throws JoseException {
JsonWebKey popKey = EcJwkGenerator.generateJwk(EllipticCurves.P256);
// generate a unique kid for the newly generated key
String kid = new BigInteger(130, random).toString(32);
popKey.setKeyId(kid);
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getRsAud());
req.setClientID(config.getClientId());
req.setClientSecret(config.getClientSecret());
req.setScopes(config.getRsScopes());
// add key to the request so that public part can be sent to AS
req.setKey(popKey);
Response response;
try {
// send token request to AS and include the public key
response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getAsCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getAsPskIdentity(), config.getAsPskKey().getBytes());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), response.getOptions().getContentFormat());
String accessToken = tokenResponse.getAccessToken();
EllipticCurveJsonWebKey rpk = tokenResponse.getRpk();
if(rpk != null) {
String keyType = rpk.getKeyType();
PublicKey publicKey = null;
if(keyType.equalsIgnoreCase("ec")) {
EllipticCurveJsonWebKey ecjwk = new EllipticCurveJsonWebKey((ECPublicKey) rpk.getKey());
publicKey = ecjwk.getPublicKey();
}
else if(keyType.equalsIgnoreCase("rsa")) {
RsaJsonWebKey rsajwk = new RsaJsonWebKey((RSAPublicKey) rpk.getKey());
publicKey = rsajwk.getPublicKey();
}
ArrayList<PublicKey> trustedPublicKeys = new ArrayList<PublicKey>();
trustedPublicKeys.add(publicKey);
// send key to resource servers authz-info resource over unencrypted DTLS
Request authzInfoRequest = Request.newPost();
authzInfoRequest.setURI("coap://localhost:"+config.getRsCoapPort()+"/"+Constants.AUTHZ_INFO_RESOURCE);
authzInfoRequest.getOptions().setContentFormat(Constants.MediaTypeRegistry_APPLICATION_JWT);
authzInfoRequest.setPayload(accessToken.getBytes());
Response authzInfoResponse = authzInfoRequest.send().waitForResponse();
if(authzInfoResponse.getCode() == ResponseCode.CREATED) {
// get the temperature
response = DTLSUtils.dtlsRPKRequest("coaps://localhost:"+config.getRsCoapsPort()+"/temperature", "POST", "".getBytes(), MediaTypeRegistry.APPLICATION_JSON, popKey, trustedPublicKeys);
TemperatureResponse temperatureResponse = new TemperatureResponse(response.getPayload(), response.getOptions().getContentFormat());
logger.info("Temp: " + temperatureResponse);
}
else {
logger.info("Access token not valid. Response code: " + response.getCode());
}
}
} catch (Exception e) {
logger.error(e);
}
}