public static String getFilePassword(File file) throws FileException, FileNotFoundException 
    {
        FileInputStream fstream;
        fstream = new FileInputStream(file);
        final DataInputStream in = new DataInputStream(fstream);
        final BufferedReader br = new BufferedReader(new InputStreamReader(in));
        try 
        {
            final String firstLine = br.readLine();
            if (firstLine == null || firstLine.isEmpty()) {
                throw new FileException(String.format("The file: %f is missing header.", file.getName()));
            }

            if (firstLine.startsWith(SchemaSettings.SCHEMA_VERSION_KEY) || firstLine.startsWith("Date")) {
                // Not encrypted
                return "";
            }
            
            final String decrypted = FileEncryption.decrypt(firstLine);
            
            final String[] tokens = decrypted.split(",");
            if (tokens.length == 0 || tokens.length != SchemaSettings.SCHEMA_TOKEN_LENGTH) {
                throw new FileException(String.format("Unable to determine file format. The file: %f is corrupt.", file.getName()));
            }
            final String password = tokens[3];
            return password;
        } catch (GeneralSecurityException e) {
            throw new FileException("Could not decrypt file: " + file.getName(), e);
        } catch (IOException e) {
            throw new FileException("Failed to read file: " + file.getName(), e);
        } finally {
            try {
                in.close();
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }