public KeePassFile openDatabase(String password, InputStream keyFileStream) {
        if (password == null) {
            throw new IllegalArgumentException(MSG_EMPTY_MASTER_KEY);
        }
        if (keyFileStream == null) {
            throw new IllegalArgumentException("You must provide a non-empty KeePass keyfile stream.");
        }

        try {
            byte[] passwordBytes = password.getBytes(UTF_8);
            byte[] hashedPassword = Sha256.hash(passwordBytes);
            byte[] protectedBuffer = new KeyFileReader().readKeyFile(keyFileStream);

            return new KeePassDatabaseReader(keepassHeader).decryptAndParseDatabase(ByteUtils.concat(hashedPassword, protectedBuffer), keepassFile);
        } catch (UnsupportedEncodingException e) {
            throw new UnsupportedOperationException(MSG_UTF8_NOT_SUPPORTED, e);
        }
    }
public KeePassFile openDatabase ( String password , InputStream keyFileStream ) { if ( password == null ) { throw new IllegalArgumentException ( MSG_EMPTY_MASTER_KEY ) ; } if ( keyFileStream == null ) { throw new IllegalArgumentException ( "You must provide a non-empty KeePass keyfile stream." ) ; } try { byte [ ] passwordBytes = password . getBytes ( UTF_8 ) ; byte [ ] hashedPassword = Sha256 . hash ( passwordBytes ) ; byte [ ] protectedBuffer = new KeyFileReader ( ) . readKeyFile ( keyFileStream ) ; return new KeePassDatabaseReader ( keepassHeader ) . decryptAndParseDatabase ( ByteUtils . concat ( hashedPassword , protectedBuffer ) , keepassFile ) ; } catch ( UnsupportedEncodingException e ) { throw new UnsupportedOperationException ( MSG_UTF8_NOT_SUPPORTED , e ) ; } }
Opens a KeePass database with the given password and keyfile stream and
returns the KeePassFile for further processing.
<p>
If the database cannot be decrypted with the provided password and
keyfile stream an exception will be thrown.

@param password
the password to open the database
@param keyFileStream
the keyfile to open the database as stream
@return a KeePassFile
@see KeePassFile