Package com.nimbusds.jose

Examples of com.nimbusds.jose.JOSEException


      return 132;
   
    } else {

      throw new JOSEException("Unsupported ECDSA algorithm, must be ES256, ES384 or ES512");
    }
  }
View Full Code Here


      oid = SECObjectIdentifiers.secp521r1;
      digest = new SHA512Digest();

    } else {
      throw new JOSEException("Unsupported ECDSA algorithm, must be ES256, ES384 or ES512");
    }

    X9ECParameters x9ECParams = SECNamedCurves.getByOID(oid);

    return new ECDSAParameters(x9ECParams, digest);
View Full Code Here

      System.arraycopy(signatureBytes, 0, rBytes, 0, rBytes.length);
      System.arraycopy(signatureBytes, rBytes.length, sBytes, 0, sBytes.length);

    } catch (Exception e) {

      throw new JOSEException("Invalid ECDSA signature format: " + e.getMessage(), e);
    }

    BigInteger r = new BigInteger(1, rBytes);
    BigInteger s = new BigInteger(1, sBytes);
View Full Code Here

      // java.security.NoSuchAlgorithmException
      // java.security.NoSuchPaddingException
      // java.security.InvalidKeyException
      // javax.crypto.IllegalBlockSizeException
      // javax.crypto.BadPaddingException
      throw new JOSEException(e.getMessage(), e);
    }
  }
View Full Code Here

      // java.security.NoSuchAlgorithmException
      // java.security.NoSuchPaddingException
      // java.security.InvalidKeyException
      // javax.crypto.IllegalBlockSizeException
      // javax.crypto.BadPaddingException
      throw new JOSEException(e.getMessage(), e);
    }
  }
View Full Code Here

    try {
      outputOffset += cipher.doFinal(output, outputOffset);

    } catch (InvalidCipherTextException e) {

      throw new JOSEException("Couldn't generate GCM authentication tag: " + e.getMessage(), e);
    }

    // Split output into cipher text and authentication tag
    int authTagLength = AUTH_TAG_BIT_LENGTH / 8;
View Full Code Here

    try {
      outputOffset += cipher.doFinal(output, outputOffset);
       
    } catch (InvalidCipherTextException e) {

      throw new JOSEException("Couldn't validate GCM authentication tag: " + e.getMessage(), e);
    }

    return output;
  }
View Full Code Here

    try {
      verifier.initVerify(publicKey);

    } catch (InvalidKeyException e) {

      throw new JOSEException("Invalid public RSA key: " + e.getMessage(), e);
    }

    try {
      verifier.update(signedContent);
      return verifier.verify(signature.decode());
View Full Code Here

    super(SUPPORTED_ALGORITHMS, SUPPORTED_ENCRYPTION_METHODS);

    if (! key.getAlgorithm().equals("AES")) {

      throw new JOSEException("The algorithm of the shared symmetric key must be AES");
    }
   

    byte[] keyBytes = key.getEncoded();

    if (keyBytes.length != 16 &&
        keyBytes.length != 24 &&
        keyBytes.length != 32 &&
        keyBytes.length != 48 &&
        keyBytes.length != 64) {

      throw new JOSEException("The length of the shared symmetric key must be 128 bits (16 bytes), 192 bits (24 bytes), 256 bits (32 bytes), 384 bits (48 bytes) or 512 bites (64 bytes)");
    }

    cek = key;
  }
View Full Code Here

    throws JOSEException {

    // Validate required JWE parts
    if (encryptedKey != null) {

      throw new JOSEException("Unexpected encrypted key, must be omitted");
   

    if (iv == null) {

      throw new JOSEException("The initialization vector (IV) must not be null");
    }

    if (authTag == null) {

      throw new JOSEException("The authentication tag must not be null");
    }
   

    JWEAlgorithm alg = header.getAlgorithm();

    if (! alg.equals(JWEAlgorithm.DIR)) {

      throw new JOSEException("Unsupported algorithm, must be \"dir\"");
    }

    if (! critParamChecker.headerPasses(header)) {

      throw new JOSEException("Unsupported critical header parameter");
    }

    // Compose the AAD
    byte[] aad = StringUtils.toByteArray(header.toBase64URL().toString());

    // Decrypt the cipher text according to the JWE enc
    EncryptionMethod enc = header.getEncryptionMethod();

    byte[] plainText;

    if (enc.equals(EncryptionMethod.A128CBC_HS256) || enc.equals(EncryptionMethod.A192CBC_HS384) || enc.equals(EncryptionMethod.A256CBC_HS512)) {

      plainText = AESCBC.decryptAuthenticated(getKey(), iv.decode(), cipherText.decode(), aad, authTag.decode(), contentEncryptionProvider, macProvider);

    } else if (enc.equals(EncryptionMethod.A128GCM) || enc.equals(EncryptionMethod.A192GCM) || enc.equals(EncryptionMethod.A256GCM)) {

      plainText = AESGCM.decrypt(getKey(), iv.decode(), cipherText.decode(), aad, authTag.decode(), contentEncryptionProvider);

    } else {

      throw new JOSEException("Unsupported encryption method, must be A128CBC_HS256, A192CBC_HS384, A256CBC_HS512, A128GCM, A192GCM or A128GCM");
    }


    // Apply decompression if requested
    return DeflateHelper.applyDecompression(header, plainText);
View Full Code Here

TOP

Related Classes of com.nimbusds.jose.JOSEException

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.