use of java.util.Base64.Decoder in project spring-security by spring-projects.
the class NimbusReactiveJwtDecoderTests method withJwkSetUriWhenUsingCustomTypeHeaderThenRefuseOmittedType.
// gh-8730
@Test
public void withJwkSetUriWhenUsingCustomTypeHeaderThenRefuseOmittedType() {
WebClient webClient = mockJwkSetResponse(this.jwkSet);
// @formatter:off
NimbusReactiveJwtDecoder decoder = NimbusReactiveJwtDecoder.withJwkSetUri(this.jwkSetUri).webClient(webClient).jwtProcessorCustomizer((p) -> p.setJWSTypeVerifier(new DefaultJOSEObjectTypeVerifier<>(new JOSEObjectType("JWS")))).build();
assertThatExceptionOfType(BadJwtException.class).isThrownBy(() -> decoder.decode(this.messageReadToken).block()).havingRootCause().withMessage("Required JOSE header typ (type) parameter is missing");
// @formatter:on
}
use of java.util.Base64.Decoder in project spring-security by spring-projects.
the class NimbusReactiveJwtDecoderTests method withSecretKeyWhenUsingCustomTypeHeaderThenRefuseOmittedType.
// gh-8730
@Test
public void withSecretKeyWhenUsingCustomTypeHeaderThenRefuseOmittedType() {
SecretKey secretKey = TestKeys.DEFAULT_SECRET_KEY;
// @formatter:off
NimbusReactiveJwtDecoder decoder = NimbusReactiveJwtDecoder.withSecretKey(secretKey).jwtProcessorCustomizer((p) -> p.setJWSTypeVerifier(new DefaultJOSEObjectTypeVerifier<>(new JOSEObjectType("JWS")))).build();
assertThatExceptionOfType(BadJwtException.class).isThrownBy(() -> decoder.decode(this.messageReadToken).block()).havingRootCause().withMessage("Required JOSE header typ (type) parameter is missing");
// @formatter:on
}
use of java.util.Base64.Decoder in project vorto by eclipse.
the class PublicKeyHelper method toPublicKey.
public static PublicKey toPublicKey(String mod, String exp) {
try {
Decoder urlDecoder = Base64.getUrlDecoder();
BigInteger modulus = new BigInteger(1, urlDecoder.decode(mod));
BigInteger publicExponent = new BigInteger(1, urlDecoder.decode(exp));
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
} catch (Exception e) {
throw new InvalidTokenException("Problem converting the common keys to public keys", e);
}
}
use of java.util.Base64.Decoder in project cu-kfs by CU-CommunityApps.
the class CuCapAssetInventoryServerAuthFilter method decodePublicKey.
private PublicKey decodePublicKey(JsonObject publicKeyJson) throws NoSuchAlgorithmException, InvalidKeySpecException {
String keyModuloN = publicKeyJson.get(CuCamsConstants.CapAssetApi.COGNITO_PUBLIC_KEY_MODULO).getAsString();
String keyExponentE = publicKeyJson.get(CuCamsConstants.CapAssetApi.COGNITO_PUBLIC_KEY_EXPONENT).getAsString();
Base64.Decoder decoder = Base64.getUrlDecoder();
BigInteger modulus = new BigInteger(1, decoder.decode(keyModuloN));
BigInteger publicExponent = new BigInteger(1, decoder.decode(keyExponentE));
RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(modulus, publicExponent);
return KeyFactory.getInstance(CuCamsConstants.CapAssetApi.RSA).generatePublic(publicKeySpec);
}
Aggregations