Package com.nimbusds.jose.util

Examples of com.nimbusds.jose.util.Base64URL


    if (! critParamChecker.headerPasses(header)) {
      return false;
    }

    byte[] hmac = HMAC.compute(jcaAlg, getSharedSecret(), signedContent, provider);
    Base64URL expectedSignature = Base64URL.encode(hmac);
    return expectedSignature.equals(signature);
  }
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

    byte[] epu = null;

    if (header.getCustomParameter("epu") instanceof String) {

      epu = new Base64URL((String)header.getCustomParameter("epu")).decode();
    }

    byte[] epv = null;

    if (header.getCustomParameter("epv") instanceof String) {

      epv = new Base64URL((String)header.getCustomParameter("epv")).decode();
    }

    // Generate alternative CEK using concat-KDF
    SecretKey altCEK = ConcatKDF.generateCEK(secretKey, header.getEncryptionMethod(), epu, epv);
View Full Code Here

    byte[] epu = null;

    if (header.getCustomParameter("epu") instanceof String) {

      epu = new Base64URL((String)header.getCustomParameter("epu")).decode();
    }

    byte[] epv = null;

    if (header.getCustomParameter("epv") instanceof String) {

      epv = new Base64URL((String)header.getCustomParameter("epv")).decode();
    }

    SecretKey cekAlt = ConcatKDF.generateCEK(secretKey, header.getEncryptionMethod(), epu, epv);

    final byte[] plainText = AESCBC.decrypt(cekAlt, iv.decode(), cipherText.decode(), ceProvider);
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

    if (enc.cekBitLength() != getKey().getEncoded().length * 8) {

      throw new JOSEException("The Content Encryption Key (CEK) length must be " + enc.cekBitLength() + " bits for " + enc + " encryption");
    }

    final Base64URL encryptedKey = null; // The second JWE part


    // Apply compression if instructed
    byte[] plainText = DeflateHelper.applyCompression(readOnlyJWEHeader, bytes);

View Full Code Here

  public void testFullConstructorAndSerialization()
    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<Base64>();
    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,
                      KeyUse.SIGNATURE, null, JWSAlgorithm.RS256, "1",
                      x5u, x5t, x5c);
   
    // Test getters
    assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
    assertNull(key.getKeyOperations());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());
    assertEquals(x5u.toString(), key.getX509CertURL().toString());
    assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
    assertEquals(x5c.size(), key.getX509CertChain().size());

    assertEquals(new Base64URL(n), key.getModulus());
    assertEquals(new Base64URL(e), key.getPublicExponent());

    assertEquals(new Base64URL(d), key.getPrivateExponent());

    assertEquals(new Base64URL(p), key.getFirstPrimeFactor());
    assertEquals(new Base64URL(q), key.getSecondPrimeFactor());

    assertEquals(new Base64URL(dp), key.getFirstFactorCRTExponent());
    assertEquals(new Base64URL(dq), key.getSecondFactorCRTExponent());

    assertEquals(new Base64URL(qi), key.getFirstCRTCoefficient());

    assertTrue(key.getOtherPrimes().isEmpty());

    assertTrue(key.isPrivate());


    String jwkString = key.toJSONObject().toString();

    key = RSAKey.parse(jwkString);

    // Test getters
    assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
    assertNull(key.getKeyOperations());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());
    assertEquals(x5u.toString(), key.getX509CertURL().toString());
    assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
    assertEquals(x5c.size(), key.getX509CertChain().size());

    assertEquals(new Base64URL(n), key.getModulus());
    assertEquals(new Base64URL(e), key.getPublicExponent());

    assertEquals(new Base64URL(d), key.getPrivateExponent());

    assertEquals(new Base64URL(p), key.getFirstPrimeFactor());
    assertEquals(new Base64URL(q), key.getSecondPrimeFactor());

    assertEquals(new Base64URL(dp), key.getFirstFactorCRTExponent());
    assertEquals(new Base64URL(dq), key.getSecondFactorCRTExponent());

    assertEquals(new Base64URL(qi), key.getFirstCRTCoefficient());

    assertTrue(key.getOtherPrimes().isEmpty());

    assertTrue(key.isPrivate());
   

    // Test conversion to public JWK

    key = key.toPublicJWK();
    assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
    assertNull(key.getKeyOperations());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());

    assertEquals(new Base64URL(n), key.getModulus());
    assertEquals(new Base64URL(e), key.getPublicExponent());

    assertNull(key.getPrivateExponent());

    assertNull(key.getFirstPrimeFactor());
    assertNull(key.getSecondPrimeFactor());
View Full Code Here

  public void testBase64Builder()
    throws Exception {

    URL x5u = new URL("http://example.com/jwk.json");
    Base64URL x5t = new Base64URL("abc");
    List<Base64> x5c = new LinkedList<Base64>();
    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)).
      firstFactorCRTExponent(new Base64URL(dp)).
      secondFactorCRTExponent(new Base64URL(dq)).
      firstCRTCoefficient(new Base64URL(qi)).
      keyUse(KeyUse.SIGNATURE).
      algorithm(JWSAlgorithm.RS256).
      keyID("1").
      x509CertURL(x5u).
      x509CertThumbprint(x5t).
      x509CertChain(x5c).
      build();

    // Test getters
    assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
    assertNull(key.getKeyOperations());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());
    assertEquals(x5u.toString(), key.getX509CertURL().toString());
    assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
    assertEquals(x5c.size(), key.getX509CertChain().size());

    assertEquals(new Base64URL(n), key.getModulus());
    assertEquals(new Base64URL(e), key.getPublicExponent());

    assertEquals(new Base64URL(d), key.getPrivateExponent());

    assertEquals(new Base64URL(p), key.getFirstPrimeFactor());
    assertEquals(new Base64URL(q), key.getSecondPrimeFactor());

    assertEquals(new Base64URL(dp), key.getFirstFactorCRTExponent());
    assertEquals(new Base64URL(dq), key.getSecondFactorCRTExponent());

    assertEquals(new Base64URL(qi), key.getFirstCRTCoefficient());

    assertTrue(key.getOtherPrimes().isEmpty());

    assertTrue(key.isPrivate());


    String jwkString = key.toJSONObject().toString();

    key = RSAKey.parse(jwkString);

    // Test getters
    assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
    assertNull(key.getKeyOperations());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());
    assertEquals(x5u.toString(), key.getX509CertURL().toString());
    assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
    assertEquals(x5c.size(), key.getX509CertChain().size());

    assertEquals(new Base64URL(n), key.getModulus());
    assertEquals(new Base64URL(e), key.getPublicExponent());

    assertEquals(new Base64URL(d), key.getPrivateExponent());

    assertEquals(new Base64URL(p), key.getFirstPrimeFactor());
    assertEquals(new Base64URL(q), key.getSecondPrimeFactor());

    assertEquals(new Base64URL(dp), key.getFirstFactorCRTExponent());
    assertEquals(new Base64URL(dq), key.getSecondFactorCRTExponent());

    assertEquals(new Base64URL(qi), key.getFirstCRTCoefficient());

    assertTrue(key.getOtherPrimes().isEmpty());

    assertTrue(key.isPrivate());
  }
View Full Code Here

  public void testObjectBuilder()
    throws Exception {

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

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

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512);
    KeyPair keyPair = keyGen.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey)keyPair.getPrivate();

    RSAKey key = new RSAKey.Builder(publicKey).
      privateKey(privateKey).
      keyUse(null).
      keyOperations(ops).
      algorithm(JWSAlgorithm.RS256).
      keyID("1").
      x509CertURL(x5u).
      x509CertThumbprint(x5t).
      x509CertChain(x5c).
      build();

    // Test getters
    assertNull(key.getKeyUse());
    assertTrue(key.getKeyOperations().contains(KeyOperation.SIGN));
    assertTrue(key.getKeyOperations().contains(KeyOperation.VERIFY));
    assertEquals(2, key.getKeyOperations().size());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());
    assertEquals(x5u.toString(), key.getX509CertURL().toString());
    assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
    assertEquals(x5c.size(), key.getX509CertChain().size());

    assertTrue(publicKey.getModulus().equals(key.getModulus().decodeToBigInteger()));
    assertTrue(publicKey.getPublicExponent().equals(key.getPublicExponent().decodeToBigInteger()));

    assertTrue(privateKey.getPrivateExponent().equals(key.getPrivateExponent().decodeToBigInteger()));

    assertTrue(key.getOtherPrimes().isEmpty());

    assertTrue(key.isPrivate());


    String jwkString = key.toJSONObject().toString();

    key = RSAKey.parse(jwkString);

    // Test getters
    assertNull(key.getKeyUse());
    assertTrue(key.getKeyOperations().contains(KeyOperation.SIGN));
    assertTrue(key.getKeyOperations().contains(KeyOperation.VERIFY));
    assertEquals(2, key.getKeyOperations().size());
    assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
    assertEquals("1", key.getKeyID());
    assertEquals(x5u.toString(), key.getX509CertURL().toString());
    assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
    assertEquals(x5c.size(), key.getX509CertChain().size());

    assertTrue(publicKey.getModulus().equals(key.getModulus().decodeToBigInteger()));
    assertTrue(publicKey.getPublicExponent().equals(key.getPublicExponent().decodeToBigInteger()));
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.