Package com.nimbusds.jose

Examples of com.nimbusds.jose.JOSEException


    try {
      return cipher.doFinal(cipherText);

    } catch (Exception e) {

      throw new JOSEException(e.getMessage(), e);
    }
  }
View Full Code Here


    byte[] plainText = decrypt(compositeKey.getAESKey(), iv, cipherText, ceProvider);

    if (! macCheckPassed) {

      throw new JOSEException("MAC check failed");
    }

    return plainText;
  }
View Full Code Here

    byte[] mac = HMAC.compute(cik, macInput.getBytes(), macProvider);

    if (! ArrayUtils.constantTimeAreEqual(authTag.decode(), mac)) {

      throw new JOSEException("HMAC integrity check failed");
    }

    return plainText;
  }
View Full Code Here

      signer.update(signingInput);
      return Base64URL.encode(signer.sign());

    } catch (InvalidKeyException e) {

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

    } catch (SignatureException e) {

      throw new JOSEException("RSA signature exception: " + e.getMessage(), e);
    }
  }
View Full Code Here

      try {
        return DeflateUtils.compress(bytes);

      } catch (Exception e) {

        throw new JOSEException("Couldn't compress plain text: " + e.getMessage(), e);
      }

    } else {

      throw new JOSEException("Unsupported compression algorithm: " + compressionAlg);
    }
  }
View Full Code Here

      try {
        return DeflateUtils.decompress(bytes);

      } catch (Exception e) {

        throw new JOSEException("Couldn't decompress plain text: " + e.getMessage(), e);
      }

    } else {

      throw new JOSEException("Unsupported compression algorithm: " + compressionAlg);
    }
  }
View Full Code Here

      mac.init(secretKey);

    } catch (NoSuchAlgorithmException e) {

      throw new JOSEException("Unsupported HMAC algorithm: " + e.getMessage(), e);

    } catch (InvalidKeyException e) {

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

    mac.update(message);

    return mac.doFinal();
View Full Code Here

     
      encryptedKey = Base64URL.encode(RSA_OAEP_256.encryptCEK(publicKey, cek, keyEncryptionProvider));
     
    } else {

      throw new JOSEException("Unsupported JWE algorithm, must be RSA1_5, RSA-OAEP, or RSA-OAEP-256");
    }


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

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

    // Encrypt the plain text according to the JWE enc
    byte[] iv;
    AuthenticatedCipherText authCipherText;
   
    if (enc.equals(EncryptionMethod.A128CBC_HS256) ||
        enc.equals(EncryptionMethod.A192CBC_HS384) ||
        enc.equals(EncryptionMethod.A256CBC_HS512)    ) {

      iv = AESCBC.generateIV(randomGen);

      authCipherText = AESCBC.encryptAuthenticated(
        cek, iv, plainText, aad,
        contentEncryptionProvider, macProvider);

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

      iv = AESGCM.generateIV(randomGen);

      authCipherText = AESGCM.encrypt(
        cek, iv, plainText, aad,
        contentEncryptionProvider);

    } else if (enc.equals(EncryptionMethod.A128CBC_HS256_DEPRECATED) ||
         enc.equals(EncryptionMethod.A256CBC_HS512_DEPRECATED)    ) {

      iv = AESCBC.generateIV(randomGen);

      authCipherText = AESCBC.encryptWithConcatKDF(
        header, cek, encryptedKey, iv, plainText,
        contentEncryptionProvider, macProvider);

    } else {

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

    return new JWECryptoParts(encryptedKey, 
                        Base64URL.encode(iv),
                        Base64URL.encode(authCipherText.getCipherText()),
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

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.