Package com.nimbusds.jose.util

Examples of com.nimbusds.jose.util.Base64


    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<>();
    x5c.add(new Base64("def"));

    RSAKey key = new RSAKey(new Base64URL(n), new Base64URL(e), new Base64URL(d),
                      new Base64URL(p), new Base64URL(q),
                      new Base64URL(dp), new Base64URL(dq), new Base64URL(qi),
                      null,
View Full Code Here


    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<>();
    x5c.add(new Base64("def"));

    RSAKey key = new RSAKey.Builder(new Base64URL(n), new Base64URL(e)).
      privateExponent(new Base64URL(d)).
      firstPrimeFactor(new Base64URL(p)).
      secondPrimeFactor(new Base64URL(q)).
View Full Code Here

    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<>();
    x5c.add(new Base64("def"));

    Set<KeyOperation> ops = new LinkedHashSet<>(Arrays.asList(KeyOperation.SIGN, KeyOperation.VERIFY));

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
View Full Code Here

    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());

    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());
View Full Code Here

      jwkURL(new URL("http://example.com/jwk.json")).
      jwk(new OctetSequenceKey.Builder(new Base64URL("xyz")).build()).
      x509CertURL(new URL("http://example.com/cert.pem")).
      x509CertThumbprint(new Base64URL("abc")).
      x509CertSHA256Thumbprint(new Base64URL("abc256")).
      x509CertChain(Arrays.asList(new Base64("abc"), new Base64("def"))).
      keyID("123").
      customParam("exp", 123).
      customParam("nbf", 456).
      build();
View Full Code Here

    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());

    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());
View Full Code Here

      jwkURL(new URL("http://example.com/jwk.json")).
      jwk(new OctetSequenceKey.Builder(new Base64URL("xyz")).build()).
      x509CertURL(new URL("http://example.com/cert.pem")).
      x509CertThumbprint(new Base64URL("abc")).
      x509CertSHA256Thumbprint(new Base64URL("abc256")).
      x509CertChain(Arrays.asList(new Base64("abc"), new Base64("def"))).
      keyID("123").
      compressionAlgorithm(CompressionAlgorithm.DEF).
      agreementPartyUInfo(new Base64URL("qwe")).
      agreementPartyVInfo(new Base64URL("rty")).
      pbes2Salt(new Base64URL("uiop")).
View Full Code Here

    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<>();
    x5c.add(new Base64("def"));

    Set<KeyOperation> ops = null;

    ECKey key = new ECKey(ExampleKeyP256.CRV, ExampleKeyP256.X, ExampleKeyP256.Y, ExampleKeyP256.D,
                    KeyUse.SIGNATURE, ops, JWSAlgorithm.ES256, "1", x5u, x5t, x5c);
View Full Code Here

    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<>();
    x5c.add(new Base64("def"));

    KeyUse use = null;
    Set<KeyOperation> ops = new LinkedHashSet<>(Arrays.asList(KeyOperation.SIGN, KeyOperation.VERIFY));

    ECKey key = new ECKey(ExampleKeyP256.CRV, ExampleKeyP256.X, ExampleKeyP256.Y, ExampleKeyP256.D,
View Full Code Here

    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<>();
    x5c.add(new Base64("def"));

    ECKey key = new ECKey.Builder(ECKey.Curve.P_256, ExampleKeyP256.X, ExampleKeyP256.Y).
      d(ExampleKeyP256.D).
      keyUse(KeyUse.SIGNATURE).
      algorithm(JWSAlgorithm.ES256).
View Full Code Here

TOP

Related Classes of com.nimbusds.jose.util.Base64

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.