diff --git a/securedpreferencestore/build.gradle b/securedpreferencestore/build.gradle index e492e33..c6c939d 100644 --- a/securedpreferencestore/build.gradle +++ b/securedpreferencestore/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: "com.jfrog.bintray" -version = "0.4.0" +version = "0.4.1" android { compileSdkVersion 25 buildToolsVersion '25.0.2' @@ -10,7 +10,7 @@ android { defaultConfig { minSdkVersion 18 targetSdkVersion 25 - versionCode 6 + versionCode 7 versionName version } buildTypes { diff --git a/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/EncryptionManager.java b/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/EncryptionManager.java index e0a9c10..721e619 100644 --- a/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/EncryptionManager.java +++ b/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/EncryptionManager.java @@ -6,7 +6,6 @@ import android.os.Build; import android.security.KeyPairGeneratorSpec; import android.security.keystore.KeyGenParameterSpec; -import android.security.keystore.KeyPermanentlyInvalidatedException; import android.security.keystore.KeyProperties; import android.util.Base64; @@ -136,7 +135,6 @@ public EncryptionManager(Context context, SharedPreferences prefStore, SecuredPr boolean isRecoverableError(T error){ return (error instanceof KeyStoreException) || (error instanceof UnrecoverableEntryException) - || (error instanceof KeyPermanentlyInvalidatedException) || (error instanceof InvalidKeyException) || (error instanceof IllegalStateException) || (error instanceof IOException && (error.getCause() != null && error.getCause() instanceof BadPaddingException)) diff --git a/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java b/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java index 9ccf2a9..722e73d 100644 --- a/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java +++ b/securedpreferencestore/src/main/java/devliving/online/securedpreferencestore/SecuredPreferenceStore.java @@ -82,23 +82,23 @@ public Map getAll() { } @Override - public String getString(String s, String s1) { + public String getString(String key, String defValue) { try { - String key = EncryptionManager.getHashed(s); - String value = mPrefs.getString(key, null); + String hashedKey = EncryptionManager.getHashed(key); + String value = mPrefs.getString(hashedKey, null); if (value != null) return mEncryptionManager.decrypt(value); } catch (Exception e) { e.printStackTrace(); } - return s1; + return defValue; } @Override - public Set getStringSet(String s, Set set) { + public Set getStringSet(String key, Set defValues) { try { - String key = EncryptionManager.getHashed(s); - Set eSet = mPrefs.getStringSet(key, null); + String hashedKey = EncryptionManager.getHashed(key); + Set eSet = mPrefs.getStringSet(hashedKey, null); if (eSet != null) { Set dSet = new HashSet<>(eSet.size()); @@ -114,47 +114,47 @@ public Set getStringSet(String s, Set set) { e.printStackTrace(); } - return set; + return defValues; } @Override - public int getInt(String s, int i) { - String value = getString(s, null); + public int getInt(String key, int defValue) { + String value = getString(key, null); if (value != null) { return Integer.parseInt(value); } - return i; + return defValue; } @Override - public long getLong(String s, long l) { - String value = getString(s, null); + public long getLong(String key, long defValue) { + String value = getString(key, null); if (value != null) { return Long.parseLong(value); } - return l; + return defValue; } @Override - public float getFloat(String s, float v) { - String value = getString(s, null); + public float getFloat(String key, float defValue) { + String value = getString(key, null); if (value != null) { return Float.parseFloat(value); } - return v; + return defValue; } @Override - public boolean getBoolean(String s, boolean b) { - String value = getString(s, null); + public boolean getBoolean(String key, boolean defValue) { + String value = getString(key, null); if (value != null) { return Boolean.parseBoolean(value); } - return b; + return defValue; } - public byte[] getBytes(String s) { - String val = getString(s, null); + public byte[] getBytes(String key) { + String val = getString(key, null); if (val != null) { return EncryptionManager.base64Decode(val); } @@ -163,10 +163,10 @@ public byte[] getBytes(String s) { } @Override - public boolean contains(String s) { + public boolean contains(String key) { try { - String key = EncryptionManager.getHashed(s); - return mPrefs.contains(key); + String hashedKey = EncryptionManager.getHashed(key); + return mPrefs.contains(hashedKey); } catch (Exception e) { e.printStackTrace(); } @@ -199,11 +199,11 @@ public Editor() { } @Override - public SharedPreferences.Editor putString(String s, String s1) { + public SharedPreferences.Editor putString(String key, String value) { try { - String key = EncryptionManager.getHashed(s); - String value = mEncryptionManager.encrypt(s1); - mEditor.putString(key, value); + String hashedKey = EncryptionManager.getHashed(key); + String evalue = mEncryptionManager.encrypt(value); + mEditor.putString(hashedKey, evalue); } catch (Exception e) { e.printStackTrace(); } @@ -212,16 +212,16 @@ public SharedPreferences.Editor putString(String s, String s1) { } @Override - public SharedPreferences.Editor putStringSet(String s, Set set) { + public SharedPreferences.Editor putStringSet(String key, Set values) { try { - String key = EncryptionManager.getHashed(s); - Set eSet = new HashSet(set.size()); + String hashedKey = EncryptionManager.getHashed(key); + Set eSet = new HashSet(values.size()); - for (String val : set) { + for (String val : values) { eSet.add(mEncryptionManager.encrypt(val)); } - mEditor.putStringSet(key, eSet); + mEditor.putStringSet(hashedKey, eSet); } catch (Exception e) { e.printStackTrace(); } @@ -230,41 +230,41 @@ public SharedPreferences.Editor putStringSet(String s, Set set) { } @Override - public SharedPreferences.Editor putInt(String s, int i) { - String val = Integer.toString(i); - return putString(s, val); + public SharedPreferences.Editor putInt(String key, int value) { + String val = Integer.toString(value); + return putString(key, val); } @Override - public SharedPreferences.Editor putLong(String s, long l) { - String val = Long.toString(l); - return putString(s, val); + public SharedPreferences.Editor putLong(String key, long value) { + String val = Long.toString(value); + return putString(key, val); } @Override - public SharedPreferences.Editor putFloat(String s, float v) { - String val = Float.toString(v); - return putString(s, val); + public SharedPreferences.Editor putFloat(String key, float value) { + String val = Float.toString(value); + return putString(key, val); } @Override - public SharedPreferences.Editor putBoolean(String s, boolean b) { - String val = Boolean.toString(b); - return putString(s, val); + public SharedPreferences.Editor putBoolean(String key, boolean value) { + String val = Boolean.toString(value); + return putString(key, val); } - public SharedPreferences.Editor putBytes(String s, byte[] bytes) { + public SharedPreferences.Editor putBytes(String key, byte[] bytes) { if (bytes != null) { String val = EncryptionManager.base64Encode(bytes); - return putString(s, val); - } else return remove(s); + return putString(key, val); + } else return remove(key); } @Override - public SharedPreferences.Editor remove(String s) { + public SharedPreferences.Editor remove(String key) { try { - String key = EncryptionManager.getHashed(s); - mEditor.remove(key); + String hashedKey = EncryptionManager.getHashed(key); + mEditor.remove(hashedKey); } catch (Exception e) { e.printStackTrace(); }