Package com.nimbusds.jose.util

Examples of com.nimbusds.jose.util.Base64URL


      criticalParams(crit).
      build();

    assertEquals(3, h.getCriticalParams().size());

    Base64URL b64url = h.toBase64URL();

    // Parse back
    h = JWSHeader.parse(b64url);
   
    crit = h.getCriticalParams();
View Full Code Here


    JWSHeader h = new JWSHeader.Builder(JWSAlgorithm.HS256).
      type(JOSEObjectType.JWS).
      contentType("application/json").
      criticalParams(new HashSet<>(Arrays.asList("exp", "nbf"))).
      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

  public void testBase64URLConstructor()
    throws Exception {

    JWSHeader header = new JWSHeader(JWSAlgorithm.RS256);

    Base64URL firstPart = header.toBase64URL();
    Base64URL secondPart = new Base64URL("abc");
    Base64URL thirdPart = new Base64URL("def");

    JWSObject jws = new JWSObject(firstPart, secondPart, thirdPart);

    assertEquals(firstPart, jws.getHeader().toBase64URL());
    assertEquals(secondPart, jws.getPayload().toBase64URL());
View Full Code Here

    JWSHeader header = new JWSHeader(JWSAlgorithm.HS256);

    JWSObject jwsObject = new JWSObject(header, new Payload("Hello world!"));

    Base64URL signingInput = Base64URL.encode(jwsObject.getSigningInput());

    assertTrue(signingInput.equals(Base64URL.encode(jwsObject.getSigningInput())));

    jwsObject.sign(new MACSigner("1234567890abc"));

    String output = jwsObject.serialize();
View Full Code Here

    if (dot3 == -1) {

      // Two dots only? -> We have a JWS
      Base64URL[] parts = new Base64URL[3];
      parts[0] = new Base64URL(s.substring(0, dot1));
      parts[1] = new Base64URL(s.substring(dot1 + 1, dot2));
      parts[2] = new Base64URL(s.substring(dot2 + 1));
      return parts;
    }

    // Fourth final dot for JWE
    final int dot4 = s.indexOf(".", dot3 + 1);

    if (dot4 == -1) {
      throw new ParseException("Invalid serialized JWE object: Missing fourth delimiter", 0);
    }

    if (dot4 != -1 && s.indexOf(".", dot4 + 1) != -1) {
      throw new ParseException("Invalid serialized plain/JWS/JWE object: Too many part delimiters", 0);
    }

    // Four dots -> five parts
    Base64URL[] parts = new Base64URL[5];
    parts[0] = new Base64URL(s.substring(0, dot1));
    parts[1] = new Base64URL(s.substring(dot1 + 1, dot2));
    parts[2] = new Base64URL(s.substring(dot2 + 1, dot3));
    parts[3] = new Base64URL(s.substring(dot3 + 1, dot4));
    parts[4] = new Base64URL(s.substring(dot4 + 1));
    return parts;
  }
View Full Code Here

  public void testParse1()
    throws Exception {

    // Example header from JWE spec
    // {"alg":"RSA-OAEP","enc":"A256GCM"}
    Base64URL in = new Base64URL("eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ");

    JWEHeader h = JWEHeader.parse(in);

    assertEquals(in, h.toBase64URL());
View Full Code Here

  public void testParse2()
    throws Exception {

    // Example header from JWE spec
    // {"alg":"RSA1_5","enc":"A128CBC-HS256"}
    Base64URL in = new Base64URL("eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0");

    JWEHeader h = JWEHeader.parse(in);

    assertEquals(in, h.toBase64URL());
View Full Code Here


  public void testSerializeAndParse()
    throws Exception {

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

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

      criticalParams(crit).
      build();

    assertEquals(3, h.getCriticalParams().size());

    Base64URL b64url = h.toBase64URL();

    // Parse back
    h = JWEHeader.parse(b64url);
   
    crit = h.getCriticalParams();
View Full Code Here

    JWEHeader h = new JWEHeader.Builder(JWEAlgorithm.A128KW, EncryptionMethod.A128GCM).
      type(JOSEObjectType.JWS).
      contentType("application/json").
      criticalParams(new HashSet<>(Arrays.asList("exp", "nbf"))).
      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")).
      pbes2Count(1000).
      iv(new Base64URL("101010")).
      authTag(new Base64URL("202020")).
      customParam("exp", 123).
      customParam("nbf", 456).
      build();

    assertEquals(JWEAlgorithm.A128KW, h.getAlgorithm());
View Full Code Here

TOP

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

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.