From 68dc0893ca5823186cbc08e0d92d0f3803cb0500 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Sun, 17 Aug 2014 16:06:12 +0200 Subject: [PATCH] Some fixes --- app/app.iml | 20 ++++++++++++++++++- .../info/nerull7/mysqlbrowser/Crypto.java | 15 ++++++-------- .../mysqlbrowser/ElementArrayAdapter.java | 4 ---- .../mysqlbrowser/SettingsFragment.java | 9 ++++++--- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/app.iml b/app/app.iml index 219a04b..20413bf 100644 --- a/app/app.iml +++ b/app/app.iml @@ -56,7 +56,25 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/Crypto.java b/app/src/main/java/info/nerull7/mysqlbrowser/Crypto.java index 7f93f0d..0ad320e 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/Crypto.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/Crypto.java @@ -23,6 +23,8 @@ import javax.crypto.SecretKey; /** * Created by nerull7 on 28.07.14. + * + * Class delegated to encrypt data */ public class Crypto { private static final String KEY_FILE = "null_file"; // to trick h4x0r5 @@ -44,23 +46,19 @@ public class Crypto { } } - private SecretKey generateKey() throws NoSuchAlgorithmException { + private void generateKey() throws NoSuchAlgorithmException { SecureRandom secureRandom = new SecureRandom(); KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM); keyGenerator.init(OUTPUT_KEY_LENGTH, secureRandom); - SecretKey secretKey = keyGenerator.generateKey(); - - return secretKey; + secretKey = keyGenerator.generateKey(); } private void getSecretKey() throws NoSuchAlgorithmException, IOException, ClassNotFoundException { - String key; - // First try to open file File keyFile = new File(context.getFilesDir(), KEY_FILE); if(!keyFile.exists()) { // new key - secretKey = generateKey(); + generateKey(); FileOutputStream fileOutputStream = new FileOutputStream(keyFile); ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(secretKey); @@ -95,7 +93,6 @@ public class Crypto { public String decryptBase64(String encodedString) throws IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { byte [] encryptedString = Base64.decode(encodedString, Base64.DEFAULT); - String decrypted = decrypt(encryptedString); - return decrypted; + return decrypt(encryptedString); } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/ElementArrayAdapter.java b/app/src/main/java/info/nerull7/mysqlbrowser/ElementArrayAdapter.java index 1793468..5f4c427 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/ElementArrayAdapter.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/ElementArrayAdapter.java @@ -50,8 +50,4 @@ public class ElementArrayAdapter extends ArrayAdapter { public List getFieldArray(){ return fields; } - - public List getValueArray(){ - return values; - } } diff --git a/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java b/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java index ba386a4..b49d179 100644 --- a/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java +++ b/app/src/main/java/info/nerull7/mysqlbrowser/SettingsFragment.java @@ -6,11 +6,14 @@ import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.Preference; import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.util.Base64; /** * Created by nerull7 on 18.07.14. + * + * Fragment for Preferences/Settings */ public class SettingsFragment extends PreferenceFragment implements NumberPickerDialog.OnNumberSetListener, Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public static final String ENTRIES_PAGE_LIMIT = "entries_limit"; @@ -35,7 +38,8 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); - preferences = getPreferenceManager().getDefaultSharedPreferences(getActivity()); + getPreferenceManager(); + preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); crypto = new Crypto(getActivity()); loadPrefs(); @@ -70,7 +74,6 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker } editor.putBoolean(SAVE_SERVER_CREDENTIALS, isEnabled); editor.apply(); - editor.commit(); if(!isEnabled) reloadLoginPrefsView(); @@ -80,7 +83,7 @@ public class SettingsFragment extends PreferenceFragment implements NumberPicker saveCredentials.setChecked(preferences.getBoolean(SAVE_SERVER_CREDENTIALS, false)); connectorUrlCredentials.setText(preferences.getString(URL_CREDENTIALS, null)); loginCredentials.setText(preferences.getString(LOGIN_CREDENTIALS, null)); - passwordCredentials.setText(preferences.getString(PASSWORD_CREDENTIALS, null));; + passwordCredentials.setText(preferences.getString(PASSWORD_CREDENTIALS, null)); } private int getEntriesPageLimit(){