private Cipher createAndInitialiseContentCipher(
            ByteBuffer encrypted,
            byte[] decryptionKeyBytes)
            throws
            PDFParseException,
            NoSuchAlgorithmException,
            NoSuchPaddingException,
            InvalidKeyException,
            InvalidAlgorithmParameterException {

        final Cipher cipher;
        if (encryptionAlgorithm.isRC4()) {
            cipher = Cipher.getInstance(CIPHER_RC4);
            cipher.init(Cipher.DECRYPT_MODE, createRC4Key(decryptionKeyBytes));
        } else if (encryptionAlgorithm.isAES()) {
            cipher = createAESCipher();
            final byte[] initialisationVector = new byte[16];
            if (encrypted.remaining() >= initialisationVector.length) {
                encrypted.get(initialisationVector);
            } else {
                throw new PDFParseException(
                        "AES encrypted stream too short - " +
                                "no room for initialisation vector");
            }

            final SecretKeySpec aesKey =
                    new SecretKeySpec(decryptionKeyBytes, KEY_AES);
            final IvParameterSpec aesIv =
                    new IvParameterSpec(initialisationVector);
            cipher.init(Cipher.DECRYPT_MODE, aesKey, aesIv);
        } else {
            throw new PDFParseException(
                    "Internal error - unhandled cipher type: " +
                            encryptionAlgorithm);
        }
        return cipher;
    }