Package com.nimbusds.jose.util

Examples of com.nimbusds.jose.util.Base64URL



  public void testConstructorWithoutHeader() {

    JWECryptoParts p = new JWECryptoParts(
      new Base64URL("abc"),
      new Base64URL("def"),
      new Base64URL("ghi"),
      new Base64URL("jkl")
    );


    assertNull(p.getHeader());
    assertEquals("abc", p.getEncryptedKey().toString());
    assertEquals("def", p.getInitializationVector().toString());
    assertEquals("ghi", p.getCipherText().toString());
    assertEquals("jkl", p.getAuthenticationTag().toString());


    p = new JWECryptoParts(null, null, new Base64URL("abc"), null);

    assertNull(p.getHeader());
    assertNull(p.getEncryptedKey());
    assertNull(p.getInitializationVector());
    assertEquals("abc", p.getCipherText().toString());
View Full Code Here


    JWEHeader header = new JWEHeader(JWEAlgorithm.A128KW, EncryptionMethod.A128GCM);

    JWECryptoParts p = new JWECryptoParts(
      header,
      new Base64URL("abc"),
      new Base64URL("def"),
      new Base64URL("ghi"),
      new Base64URL("jkl")
    );

    assertEquals(header, p.getHeader());
    assertEquals("abc", p.getEncryptedKey().toString());
    assertEquals("def", p.getInitializationVector().toString());
    assertEquals("ghi", p.getCipherText().toString());
    assertEquals("jkl", p.getAuthenticationTag().toString());

    p = new JWECryptoParts(null, null, null, new Base64URL("abc"), null);

    assertNull(p.getHeader());
    assertNull(p.getEncryptedKey());
    assertNull(p.getInitializationVector());
    assertEquals("abc", p.getCipherText().toString());
View Full Code Here

    assertEquals(123000l, signedJWT.getJWTClaimsSet().getIssueTime().getTime());
    assertEquals("https://c2id.com", signedJWT.getJWTClaimsSet().getIssuer());
    assertEquals("openid", signedJWT.getJWTClaimsSet().getStringClaim("scope"));
    assertNull(signedJWT.getSignature());

    Base64URL sigInput = Base64URL.encode(signedJWT.getSigningInput());

    JWSSigner signer = new RSASSASigner(privateKey);

    signedJWT.sign(signer);

    assertEquals(JWSObject.State.SIGNED, signedJWT.getState());
    assertNotNull(signedJWT.getSignature());

    String serializedJWT = signedJWT.serialize();

    signedJWT = SignedJWT.parse(serializedJWT);
    assertEquals(serializedJWT, signedJWT.getParsedString());

    assertEquals(JWSObject.State.SIGNED, signedJWT.getState());
    assertNotNull(signedJWT.getSignature());
    assertTrue(sigInput.equals(Base64URL.encode(signedJWT.getSigningInput())));

    JWSVerifier verifier = new RSASSAVerifier(publicKey);
    assertTrue(signedJWT.verify(verifier));
  }
View Full Code Here

  public void testBase64URLConstructor()
    throws Exception {

    // {"alg":"none"}
    Base64URL part1 = new Base64URL("eyJhbGciOiJub25lIn0");

    // {"iss":"joe","exp":1300819380,"http://example.com/is_root":true}
    Base64URL part2 = new Base64URL("eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt" +
        "cGxlLmNvbS9pc19yb290Ijp0cnVlfQ");

    PlainJWT jwt = new PlainJWT(part1, part2);

    assertEquals(Algorithm.NONE, jwt.getHeader().getAlgorithm());
View Full Code Here

    String assertionString = params.get("assertion");

    if (assertionString == null || assertionString.trim().isEmpty())
      throw new ParseException("Missing or empty \"assertion\" parameter", OAuth2Error.INVALID_REQUEST);

    return new SAML2BearerGrant(new Base64URL(assertionString));
  }
View Full Code Here


  public void testConstructorAndParser()
    throws Exception {

    Base64URL assertion = new Base64URL("abc"); // dummy XML assertion

    SAML2BearerGrant grant = new SAML2BearerGrant(assertion);
    assertEquals(GrantType.SAML2_BEARER, grant.getType());
    assertEquals(assertion, grant.getSAML2Assertion());
    assertEquals("abc", grant.getAssertion());
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

    // Generate and encrypt the CEK according to the enc method
    final SecureRandom randomGen = getSecureRandom();
    final SecretKey cek = AES.generateKey(enc.cekBitLength(), randomGen);

    Base64URL encryptedKey; // The second JWE part

    if (alg.equals(JWEAlgorithm.RSA1_5)) {

      encryptedKey = Base64URL.encode(RSA1_5.encryptCEK(publicKey, cek, keyEncryptionProvider));
View Full Code Here

   */
  public static RSAKey parse(final JSONObject jsonObject)
    throws ParseException {

    // Parse the mandatory public key parameters first
    Base64URL n = new Base64URL(JSONObjectUtils.getString(jsonObject, "n"));
    Base64URL e = new Base64URL(JSONObjectUtils.getString(jsonObject, "e"));

    // Check key type
    KeyType kty = KeyType.parse(JSONObjectUtils.getString(jsonObject, "kty"));
    if (kty != KeyType.RSA) {
      throw new ParseException("The key type \"kty\" must be RSA", 0);
    }
   
    // Parse the optional private key parameters

    // 1st private representation
    Base64URL d = null;
    if (jsonObject.containsKey("d")) {
      d = new Base64URL(JSONObjectUtils.getString(jsonObject, "d"));
    }

    // 2nd private (CRT) representation
    Base64URL p = null;
    if (jsonObject.containsKey("p")) {
      p = new Base64URL(JSONObjectUtils.getString(jsonObject, "p"));
    }
    Base64URL q = null;
    if (jsonObject.containsKey("q")) {
      q = new Base64URL(JSONObjectUtils.getString(jsonObject, "q"));
    }
    Base64URL dp = null;
    if (jsonObject.containsKey("dp")) {
      dp = new Base64URL(JSONObjectUtils.getString(jsonObject, "dp"));
    }
    Base64URL dq= null;
    if (jsonObject.containsKey("dq")) {
      dq = new Base64URL(JSONObjectUtils.getString(jsonObject, "dq"));
    }
    Base64URL qi = null;
    if (jsonObject.containsKey("qi")) {
      qi = new Base64URL(JSONObjectUtils.getString(jsonObject, "qi"));
    }
   
    List<OtherPrimesInfo> oth = null;
    if (jsonObject.containsKey("oth")) {

      JSONArray arr = JSONObjectUtils.getJSONArray(jsonObject, "oth");
      oth = new ArrayList<>(arr.size());
     
      for (Object o : arr) {

        if (o instanceof JSONObject) {
          JSONObject otherJson = (JSONObject)o;

          Base64URL r = new Base64URL(JSONObjectUtils.getString(otherJson, "r"));
          Base64URL odq = new Base64URL(JSONObjectUtils.getString(otherJson, "dq"));
          Base64URL t = new Base64URL(JSONObjectUtils.getString(otherJson, "t"));

          OtherPrimesInfo prime = new OtherPrimesInfo(r, odq, t);
          oth.add(prime);
        }
      }
    }
   
    // Get optional key use
    KeyUse use = null;

    if (jsonObject.containsKey("use")) {
      use = KeyUse.parse(JSONObjectUtils.getString(jsonObject, "use"));
    }

    // Get optional key operations
    Set<KeyOperation> ops = null;

    if (jsonObject.containsKey("key_ops")) {
      ops = KeyOperation.parse(JSONObjectUtils.getStringList(jsonObject, "key_ops"));
    }

    // Get optional intended algorithm
    Algorithm alg = null;

    if (jsonObject.containsKey("alg")) {
      alg = new Algorithm(JSONObjectUtils.getString(jsonObject, "alg"));
    }

    // Get optional key ID
    String kid = null;

    if (jsonObject.containsKey("kid")) {
      kid = JSONObjectUtils.getString(jsonObject, "kid");
    }

    // Get optional X.509 cert URL
    URL x5u = null;

    if (jsonObject.containsKey("x5u")) {
      x5u = JSONObjectUtils.getURL(jsonObject, "x5u")
    }

    // Get optional X.509 cert thumbprint
    Base64URL x5t = null;

    if (jsonObject.containsKey("x5t")) {
      x5t = new Base64URL(JSONObjectUtils.getString(jsonObject, "x5t"));
    }

    // Get optional X.509 cert chain
    List<Base64> x5c = null;

View Full Code Here

    JWSHeader header = JWSHeader.parse(B64_HEADER);

    JWSSigner signer = new RSASSASigner(PRIVATE_KEY);

    Base64URL b64sigComputed = signer.sign(header, SIGNABLE);

    assertEquals("Signature check", B64_SIG, b64sigComputed);
  }
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.