Package com.nimbusds.jose.jwk

Examples of com.nimbusds.jose.jwk.RSAKey


  private SignedAuthRequestUrlBuilder urlBuilder = new SignedAuthRequestUrlBuilder();

  @Before
  public void prepare() throws NoSuchAlgorithmException, InvalidKeySpecException {

    RSAKey key = new RSAKey(new Base64URL(n), new Base64URL(e), new Base64URL(d), KeyUse.SIGNATURE, null, new Algorithm(alg), kid, null, null, null);
    Map<String, JWK> keys = Maps.newHashMap();
    keys.put("client", key);

    signingAndValidationService = new DefaultJwtSigningAndValidationService(keys);
    signingAndValidationService.setDefaultSignerKeyId("client");
View Full Code Here


      "lXYx6RtE1n_AagjqajlkjieGlxTTThHD8Iga6foGBMaAr5uR1hGQpSc7"+
      "Gl7CF1DZkBJMTQN6EshYzZfxW08mIO8M6Rzuh0beL6fG9mkDcIyPrBXx"+
      "2bQ_mM\""+
      "}";

    RSAKey jwk = RSAKey.parse(json);


    String jwe = "eyJhbGciOiJSU0ExXzUiLCJraWQiOiJmcm9kby5iYWdnaW5zQGhvYmJpdG9uLm"+
      "V4YW1wbGUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0"+
      "."+
      "laLxI0j-nLH-_BgLOXMozKxmy9gffy2gTdvqzfTihJBuuzxg0V7yk1WClnQePF"+
      "vG2K-pvSlWc9BRIazDrn50RcRai__3TDON395H3c62tIouJJ4XaRvYHFjZTZ2G"+
      "Xfz8YAImcc91Tfk0WXC2F5Xbb71ClQ1DDH151tlpH77f2ff7xiSxh9oSewYrcG"+
      "TSLUeeCt36r1Kt3OSj7EyBQXoZlN7IxbyhMAfgIe7Mv1rOTOI5I8NQqeXXW8Vl"+
      "zNmoxaGMny3YnGir5Wf6Qt2nBq4qDaPdnaAuuGUGEecelIO1wx1BpyIfgvfjOh"+
      "MBs9M8XL223Fg47xlGsMXdfuY-4jaqVw"+
      "."+
      "bbd5sTkYwhAIqfHsx8DayA"+
      "."+
      "0fys_TY_na7f8dwSfXLiYdHaA2DxUjD67ieF7fcVbIR62JhJvGZ4_FNVSiGc_r"+
      "aa0HnLQ6s1P2sv3Xzl1p1l_o5wR_RsSzrS8Z-wnI3Jvo0mkpEEnlDmZvDu_k8O"+
      "WzJv7eZVEqiWKdyVzFhPpiyQU28GLOpRc2VbVbK4dQKPdNTjPPEmRqcaGeTWZV"+
      "yeSUvf5k59yJZxRuSvWFf6KrNtmRdZ8R4mDOjHSrM_s8uwIFcqt4r5GX8TKaI0"+
      "zT5CbL5Qlw3sRc7u_hg0yKVOiRytEAEs3vZkcfLkP6nbXdC_PkMdNS-ohP78T2"+
      "O6_7uInMGhFeX4ctHG7VelHGiT93JfWDEQi5_V9UN1rhXNrYu-0fVMkZAKX3VW"+
      "i7lzA6BP430m"+
      "."+
      "kvKuFBXHe5mQr4lqgobAUg";

    JWEObject jweObject = JWEObject.parse(jwe);

    assertEquals(JWEAlgorithm.RSA1_5, jweObject.getHeader().getAlgorithm());
    assertEquals(EncryptionMethod.A128CBC_HS256, jweObject.getHeader().getEncryptionMethod());
    assertEquals("frodo.baggins@hobbiton.example", jweObject.getHeader().getKeyID());

    JWEDecrypter decrypter = new RSADecrypter(jwk.toRSAPrivateKey());

    jweObject.decrypt(decrypter);

    assertEquals(JWEObject.State.DECRYPTED, jweObject.getState());
  }
View Full Code Here

    final Base64URL mod = new Base64URL("abc123");
    final Base64URL exp = new Base64URL("def456");
    final KeyUse use = KeyUse.ENCRYPTION;
    final String kid = "1234";

    RSAKey jwk = new RSAKey(mod, exp, use, null, JWEAlgorithm.RSA1_5, kid, null, null, null);

    List<Base64> certChain = new LinkedList<>();
    certChain.add(new Base64("asd"));
    certChain.add(new Base64("fgh"));
    certChain.add(new Base64("jkl"));

    JWSHeader h = new JWSHeader.Builder(JWSAlgorithm.RS256).
      type(new JOSEObjectType("JWT")).
      contentType("application/json").
      criticalParams(crit).
      jwkURL(new URL("https://example.com/jku.json")).
      jwk(jwk).
      x509CertURL(new URL("https://example/cert.b64")).
      x509CertThumbprint(new Base64URL("789iop")).
      x509CertSHA256Thumbprint(new Base64URL("789asd")).
      x509CertChain(certChain).
      keyID("1234").
      customParam("xCustom", "+++").
      build();


    Base64URL base64URL = h.toBase64URL();

    // Parse back
    h = JWSHeader.parse(base64URL);

    assertEquals(JWSAlgorithm.RS256, h.getAlgorithm());
    assertEquals(new JOSEObjectType("JWT"), h.getType());
    assertTrue(h.getCriticalParams().contains("iat"));
    assertTrue(h.getCriticalParams().contains("exp"));
    assertTrue(h.getCriticalParams().contains("nbf"));
    assertEquals(3, h.getCriticalParams().size());
    assertEquals("application/json", h.getContentType());
    assertEquals(new URL("https://example.com/jku.json"), h.getJWKURL());
    assertEquals("1234", h.getKeyID());

    jwk = (RSAKey)h.getJWK();
    assertNotNull(jwk);
    assertEquals(new Base64URL("abc123"), jwk.getModulus());
    assertEquals(new Base64URL("def456"), jwk.getPublicExponent());
    assertEquals(KeyUse.ENCRYPTION, jwk.getKeyUse());
    assertEquals(JWEAlgorithm.RSA1_5, jwk.getAlgorithm());
    assertEquals("1234", jwk.getKeyID());

    assertEquals(new URL("https://example/cert.b64"), h.getX509CertURL());
    assertEquals(new Base64URL("789iop"), h.getX509CertThumbprint());
    assertEquals(new Base64URL("789asd"), h.getX509CertSHA256Thumbprint());

    certChain = h.getX509CertChain();
    assertEquals(3, certChain.size());
    assertEquals(new Base64("asd"), certChain.get(0));
    assertEquals(new Base64("fgh"), certChain.get(1));
    assertEquals(new Base64("jkl"), certChain.get(2));

    assertEquals("+++", (String)h.getCustomParam("xCustom"));
    assertEquals(1, h.getCustomParams().size());

    assertEquals(base64URL, h.getParsedBase64URL());

    assertTrue(h.getIncludedParams().contains("alg"));
    assertTrue(h.getIncludedParams().contains("typ"));
    assertTrue(h.getIncludedParams().contains("cty"));
    assertTrue(h.getIncludedParams().contains("crit"));
    assertTrue(h.getIncludedParams().contains("jku"));
    assertTrue(h.getIncludedParams().contains("jwk"));
    assertTrue(h.getIncludedParams().contains("kid"));
    assertTrue(h.getIncludedParams().contains("x5u"));
    assertTrue(h.getIncludedParams().contains("x5t"));
    assertTrue(h.getIncludedParams().contains("x5c"));
    assertTrue(h.getIncludedParams().contains("xCustom"));
    assertEquals(12, h.getIncludedParams().size());

    // Test copy constructor
    h = new JWSHeader(h);

    assertEquals(JWSAlgorithm.RS256, h.getAlgorithm());
    assertEquals(new JOSEObjectType("JWT"), h.getType());
    assertTrue(h.getCriticalParams().contains("iat"));
    assertTrue(h.getCriticalParams().contains("exp"));
    assertTrue(h.getCriticalParams().contains("nbf"));
    assertEquals(3, h.getCriticalParams().size());
    assertEquals("application/json", h.getContentType());
    assertEquals(new URL("https://example.com/jku.json"), h.getJWKURL());
    assertEquals("1234", h.getKeyID());

    jwk = (RSAKey)h.getJWK();
    assertNotNull(jwk);
    assertEquals(new Base64URL("abc123"), jwk.getModulus());
    assertEquals(new Base64URL("def456"), jwk.getPublicExponent());
    assertEquals(KeyUse.ENCRYPTION, jwk.getKeyUse());
    assertEquals(JWEAlgorithm.RSA1_5, jwk.getAlgorithm());
    assertEquals("1234", jwk.getKeyID());

    assertEquals(new URL("https://example/cert.b64"), h.getX509CertURL());
    assertEquals(new Base64URL("789iop"), h.getX509CertThumbprint());
    assertEquals(new Base64URL("789asd"), h.getX509CertSHA256Thumbprint());
View Full Code Here

    final Base64URL mod = new Base64URL("abc123");
    final Base64URL exp = new Base64URL("def456");
    final KeyUse use = KeyUse.ENCRYPTION;
    final String kid = "1234";

    RSAKey jwk = new RSAKey(mod, exp, use, null, JWEAlgorithm.RSA1_5, kid, null, null, null);

    List<Base64> certChain = new LinkedList<>();
    certChain.add(new Base64("asd"));
    certChain.add(new Base64("fgh"));
    certChain.add(new Base64("jkl"));

    JWEHeader h = new JWEHeader.Builder(JWEAlgorithm.RSA1_5, EncryptionMethod.A256GCM).
      type(new JOSEObjectType("JWT")).
      compressionAlgorithm(CompressionAlgorithm.DEF).
      jwkURL(new URL("https://example.com/jku.json")).
      jwk(jwk).
      x509CertURL(new URL("https://example/cert.b64")).
      x509CertThumbprint(new Base64URL("789iop")).
      x509CertSHA256Thumbprint(new Base64URL("789asd")).
      x509CertChain(certChain).
      keyID("1234").
      agreementPartyUInfo(new Base64URL("abc")).
      agreementPartyVInfo(new Base64URL("xyz")).
      pbes2Salt(new Base64URL("omg")).
      pbes2Count(1000).
      iv(new Base64URL("101010")).
      authTag(new Base64URL("202020")).
      customParam("xCustom", "+++").
      build();


    Base64URL base64URL = h.toBase64URL();

    // Parse back
    h = JWEHeader.parse(base64URL);

    assertEquals(JWEAlgorithm.RSA1_5, h.getAlgorithm());
    assertEquals(new JOSEObjectType("JWT"), h.getType());
    assertEquals(EncryptionMethod.A256GCM, h.getEncryptionMethod());
    assertEquals(CompressionAlgorithm.DEF, h.getCompressionAlgorithm());
    assertEquals(new URL("https://example.com/jku.json"), h.getJWKURL());
    assertEquals("1234", h.getKeyID());

    jwk = (RSAKey)h.getJWK();
    assertNotNull(jwk);
    assertEquals(new Base64URL("abc123"), jwk.getModulus());
    assertEquals(new Base64URL("def456"), jwk.getPublicExponent());
    assertEquals(KeyUse.ENCRYPTION, jwk.getKeyUse());
    assertEquals(JWEAlgorithm.RSA1_5, jwk.getAlgorithm());
    assertEquals("1234", jwk.getKeyID());

    assertEquals(new URL("https://example/cert.b64"), h.getX509CertURL());
    assertEquals(new Base64URL("789iop"), h.getX509CertThumbprint());
    assertEquals(new Base64URL("789asd"), h.getX509CertSHA256Thumbprint());

    certChain = h.getX509CertChain();
    assertEquals(3, certChain.size());
    assertEquals(new Base64("asd"), certChain.get(0));
    assertEquals(new Base64("fgh"), certChain.get(1));
    assertEquals(new Base64("jkl"), certChain.get(2));

    assertEquals(new Base64URL("abc"), h.getAgreementPartyUInfo());
    assertEquals(new Base64URL("xyz"), h.getAgreementPartyVInfo());

    assertEquals(new Base64URL("omg"), h.getPBES2Salt());
    assertEquals(1000, h.getPBES2Count());

    assertEquals(new Base64URL("101010"), h.getIV());
    assertEquals(new Base64URL("202020"), h.getAuthTag());

    assertEquals("+++", (String)h.getCustomParam("xCustom"));
    assertEquals(1, h.getCustomParams().size());

    assertEquals(base64URL, h.getParsedBase64URL());

    assertTrue(h.getIncludedParams().contains("alg"));
    assertTrue(h.getIncludedParams().contains("typ"));
    assertTrue(h.getIncludedParams().contains("enc"));
    assertTrue(h.getIncludedParams().contains("zip"));
    assertTrue(h.getIncludedParams().contains("jku"));
    assertTrue(h.getIncludedParams().contains("jwk"));
    assertTrue(h.getIncludedParams().contains("kid"));
    assertTrue(h.getIncludedParams().contains("x5u"));
    assertTrue(h.getIncludedParams().contains("x5t"));
    assertTrue(h.getIncludedParams().contains("x5c"));
    assertTrue(h.getIncludedParams().contains("apu"));
    assertTrue(h.getIncludedParams().contains("apv"));
    assertTrue(h.getIncludedParams().contains("p2s"));
    assertTrue(h.getIncludedParams().contains("p2c"));
    assertTrue(h.getIncludedParams().contains("iv"));
    assertTrue(h.getIncludedParams().contains("tag"));
    assertTrue(h.getIncludedParams().contains("xCustom"));
    assertEquals(18, h.getIncludedParams().size());

    // Test copy constructor
    h = new JWEHeader(h);

    assertEquals(JWEAlgorithm.RSA1_5, h.getAlgorithm());
    assertEquals(new JOSEObjectType("JWT"), h.getType());
    assertEquals(EncryptionMethod.A256GCM, h.getEncryptionMethod());
    assertEquals(CompressionAlgorithm.DEF, h.getCompressionAlgorithm());
    assertEquals(new URL("https://example.com/jku.json"), h.getJWKURL());
    assertEquals("1234", h.getKeyID());

    jwk = (RSAKey)h.getJWK();
    assertNotNull(jwk);
    assertEquals(new Base64URL("abc123"), jwk.getModulus());
    assertEquals(new Base64URL("def456"), jwk.getPublicExponent());
    assertEquals(KeyUse.ENCRYPTION, jwk.getKeyUse());
    assertEquals(JWEAlgorithm.RSA1_5, jwk.getAlgorithm());
    assertEquals("1234", jwk.getKeyID());

    assertEquals(new URL("https://example/cert.b64"), h.getX509CertURL());
    assertEquals(new Base64URL("789iop"), h.getX509CertThumbprint());
    assertEquals(new Base64URL("789asd"), h.getX509CertSHA256Thumbprint());
View Full Code Here

    KeyPair keyPair = keyGen.generateKeyPair();

    RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();

    RSAKey rsaJWK = new RSAKey.Builder(publicKey).keyID("1").build();

    claimsSet.setSubjectJWK(rsaJWK);

    RSAKey rsaJWKOut = (RSAKey)claimsSet.getSubjectJWK();

    assertEquals(rsaJWK.getModulus(), rsaJWKOut.getModulus());
    assertEquals(rsaJWK.getPublicExponent(), rsaJWKOut.getPublicExponent());
    assertEquals(rsaJWK.getKeyID(), rsaJWKOut.getKeyID());


    String json = claimsSet.toJSONObject().toJSONString();

    System.out.println("ID token with subject JWK: " + json);

    claimsSet = IDTokenClaimsSet.parse(json);

    rsaJWKOut = (RSAKey)claimsSet.getSubjectJWK();

    assertEquals(rsaJWK.getModulus(), rsaJWKOut.getModulus());
    assertEquals(rsaJWK.getPublicExponent(), rsaJWKOut.getPublicExponent());
    assertEquals(rsaJWK.getKeyID(), rsaJWKOut.getKeyID());
  }
View Full Code Here

    KeyPair keyPair = keyGen.generateKeyPair();

    RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)keyPair.getPrivate();

    RSAKey rsaJWK = new RSAKey.Builder(publicKey).privateKey(privateKey).build();

    try {
      claimsSet.setSubjectJWK(rsaJWK);

      fail();
View Full Code Here

    meta.setTokenEndpointAuthMethod(authMethod);
   
    URI jwksURI = new URI("http://example.com/jwks.json");
    meta.setJWKSetURI(jwksURI);

    RSAKey rsaKey = new RSAKey.Builder(new Base64URL("nabc"), new Base64URL("eabc")).build();
    JWKSet jwkSet = new JWKSet(rsaKey);
    meta.setJWKSet(jwkSet);

    SoftwareID softwareID = new SoftwareID();
    meta.setSoftwareID(softwareID);
View Full Code Here

    JWSSigner signer = new RSASSASigner(rsaPrivateKey);
    jwsObject1.sign(signer);
    Base64URL sig1 = jwsObject1.getSignature();

    // Create signer from JWK representation
    RSAKey rsaJWK = new RSAKey.Builder(rsaPublicKey).privateKey(rsaPrivateKey).build();

    JWSObject jwsObject2 = new JWSObject(new JWSHeader(JWSAlgorithm.RS256), new Payload("test123"));
    signer = new RSASSASigner(rsaJWK.toRSAPrivateKey());
    jwsObject2.sign(signer);
    Base64URL sig2 = jwsObject2.getSignature();

    assertTrue("Signature comparison", sig1.equals(sig2));

    // Verifier from raw Java RSA key
    JWSVerifier verifier = new RSASSAVerifier(rsaPublicKey);
    assertTrue(jwsObject1.verify(verifier));
    assertTrue(jwsObject2.verify(verifier));

    // Verifier from JWK representation
    verifier = new RSASSAVerifier(rsaJWK.toRSAPublicKey());
    assertTrue(jwsObject1.verify(verifier));
    assertTrue(jwsObject2.verify(verifier));
  }
View Full Code Here

      "ZBKCQsMf3HaEGBjTVJs_jcK8-TRXvaKe-7ZMaQj8VfBdYkssbu0NKDDh" +
      "jJ-GtiseaDVWt7dcH0cfwxgFUHpQh7FoCrjFJ6h6ZEpMF6xmujs4qMpP" +
      "z8aaI4\"" +
      "}";

    RSAKey jwk = RSAKey.parse(json);

    String jws = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImJpbGJvLmJhZ2dpbnNAaG9iYml0b24uZX" +
      "hhbXBsZSJ9" +
      "." +
      "SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH" +
      "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk" +
      "b24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcm" +
      "UgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4" +
      "." +
      "MRjdkly7_-oTPTS3AXP41iQIGKa80A0ZmTuV5MEaHoxnW2e5CZ5NlKtainoFmK" +
      "ZopdHM1O2U4mwzJdQx996ivp83xuglII7PNDi84wnB-BDkoBwA78185hX-Es4J" +
      "IwmDLJK3lfWRa-XtL0RnltuYv746iYTh_qHRD68BNt1uSNCrUCTJDt5aAE6x8w" +
      "W1Kt9eRo4QPocSadnHXFxnt8Is9UzpERV0ePPQdLuW3IS_de3xyIrDaLGdjluP" +
      "xUAhb6L2aXic1U12podGU0KLUQSE_oI-ZnmKJ3F4uOZDnd6QZWJushZ41Axf_f" +
      "cIe8u9ipH84ogoree7vjbU5y18kDquDg";

    JWSObject jwsObject = JWSObject.parse(jws);

    assertEquals(JWSAlgorithm.RS256, jwsObject.getHeader().getAlgorithm());
    assertEquals("bilbo.baggins@hobbiton.example", jwsObject.getHeader().getKeyID());

    JWSVerifier verifier = new RSASSAVerifier(jwk.toRSAPublicKey());

    assertTrue(jwsObject.verify(verifier));

    assertEquals("SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH" +
      "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk" +
View Full Code Here

      "ZBKCQsMf3HaEGBjTVJs_jcK8-TRXvaKe-7ZMaQj8VfBdYkssbu0NKDDh" +
      "jJ-GtiseaDVWt7dcH0cfwxgFUHpQh7FoCrjFJ6h6ZEpMF6xmujs4qMpP" +
      "z8aaI4\"" +
      "}";

    RSAKey jwk = RSAKey.parse(json);

    String jws = "eyJhbGciOiJQUzM4NCIsImtpZCI6ImJpbGJvLmJhZ2dpbnNAaG9iYml0b24uZX" +
      "hhbXBsZSJ9" +
      "." +
      "SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH" +
      "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk" +
      "b24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcm" +
      "UgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4" +
      "." +
      "cu22eBqkYDKgIlTpzDXGvaFfz6WGoz7fUDcfT0kkOy42miAh2qyBzk1xEsnk2I" +
      "pN6-tPid6VrklHkqsGqDqHCdP6O8TTB5dDDItllVo6_1OLPpcbUrhiUSMxbbXU" +
      "vdvWXzg-UD8biiReQFlfz28zGWVsdiNAUf8ZnyPEgVFn442ZdNqiVJRmBqrYRX" +
      "e8P_ijQ7p8Vdz0TTrxUeT3lm8d9shnr2lfJT8ImUjvAA2Xez2Mlp8cBE5awDzT" +
      "0qI0n6uiP1aCN_2_jLAeQTlqRHtfa64QQSUmFAAjVKPbByi7xho0uTOcbH510a" +
      "6GYmJUAfmWjwZ6oD4ifKo8DYM-X72Eaw";

    JWSObject jwsObject = JWSObject.parse(jws);

    assertEquals(JWSAlgorithm.PS384, jwsObject.getHeader().getAlgorithm());
    assertEquals("bilbo.baggins@hobbiton.example", jwsObject.getHeader().getKeyID());

    JWSVerifier verifier = new RSASSAVerifier(jwk.toRSAPublicKey());

    assertTrue(jwsObject.verify(verifier));

    assertEquals("SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IH" +
      "lvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBk" +
View Full Code Here

TOP

Related Classes of com.nimbusds.jose.jwk.RSAKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.