public StandardDecrypter(
            EncryptionAlgorithm encryptionAlgorithm,
            PDFObject documentId, int keyBitLength,
            int revision, byte[] oValue, byte[] uValue, int pValue,
            boolean encryptMetadata, PDFPassword password)
            throws
            IOException,
            EncryptionUnsupportedByProductException,
            EncryptionUnsupportedByPlatformException {

        this.encryptionAlgorithm = encryptionAlgorithm;

        // The spec (sensibly) demands that the documentId be present,
        // but we'll play it safe
        final byte[] firstDocIdValue;
        if (documentId == null) {
            firstDocIdValue = null;
        } else {
            firstDocIdValue = documentId.getAt(0).getStream();
        }

        testJceAvailability(keyBitLength);

        try {
            final List<byte[]> passwordBytePossibilities =
                    password.getPasswordBytes(false);
            for (int i = 0;
                    generalKeyBytes == null && i < passwordBytePossibilities.size();
                    ++i) {
                final byte[] passwordBytes = passwordBytePossibilities.get(i);
                generalKeyBytes = checkOwnerPassword(
                        passwordBytes, firstDocIdValue, keyBitLength,
                        revision, oValue, uValue, pValue, encryptMetadata);
                if (generalKeyBytes != null) {
                    // looks like the password was the owner password!
                    ownerAuthorised = true;
                } else {
                    // try it as the user password
                    generalKeyBytes = checkUserPassword(
                            passwordBytes, firstDocIdValue, keyBitLength,
                            revision, oValue, uValue, pValue, encryptMetadata);

                }
            }
        } catch (GeneralSecurityException e) {
            // Unexpected, as our test of JCE availability should have caught
            // problems with cipher availability.
            // It may well be a problem with document content?
            throw new PDFParseException("Unable to check passwords: " +
                    e.getMessage(), e);
        }

        if (generalKeyBytes == null) {
            throw new PDFAuthenticationFailureException(
                    "Password failed authentication for both " +
                            "owner and user password");
        }

    }