@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public SharedPreferences.Editor putStringSet(String key, Set<String> values) { final Set<String> encryptedValues = new HashSet<String>(values.size()); for (String value : values) { encryptedValues.add(SecurePreferencesOld.encrypt(value)); } mEditor.putStringSet(SecurePreferencesOld.encrypt(key), encryptedValues); return this; }
@Override public boolean getBoolean(String key, boolean defaultValue) { final String encryptedValue = SecurePreferencesOld.sFile.getString(SecurePreferencesOld.encrypt(key), null); if (encryptedValue == null) { return defaultValue; } try { return Boolean.parseBoolean(SecurePreferencesOld.decrypt(encryptedValue)); } catch (NumberFormatException e) { throw new ClassCastException(e.getMessage()); } }
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public Set<String> getStringSet(String key, Set<String> defaultValues) { final Set<String> encryptedSet = SecurePreferencesOld.sFile.getStringSet(SecurePreferencesOld.encrypt(key), null); if (encryptedSet == null) { return defaultValues; } final Set<String> decryptedSet = new HashSet<String>(encryptedSet.size()); for (String encryptedValue : encryptedSet) { decryptedSet.add(SecurePreferencesOld.decrypt(encryptedValue)); } return decryptedSet; }
@Override public SharedPreferences.Editor remove(String key) { mEditor.remove(SecurePreferencesOld.encrypt(key)); return this; }
@Override public SharedPreferences.Editor putBoolean(String key, boolean value) { mEditor.putString( SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Boolean.toString(value))); return this; }
@Override public SharedPreferences.Editor putFloat(String key, float value) { mEditor.putString( SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Float.toString(value))); return this; }
@Override public SharedPreferences.Editor putLong(String key, long value) { mEditor.putString( SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Long.toString(value))); return this; }
@Override public SharedPreferences.Editor putInt(String key, int value) { mEditor.putString( SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Integer.toString(value))); return this; }
/** * This is useful for storing values that have be encrypted by something else * * @param key - encrypted as usual * @param value will not be encrypted * @return */ public SharedPreferences.Editor putStringNoEncrypted(String key, String value) { mEditor.putString(SecurePreferencesOld.encrypt(key), value); return this; }
@Override public boolean contains(String key) { return SecurePreferencesOld.sFile.contains(SecurePreferencesOld.encrypt(key)); }
/** * Added to get a values as as it can be useful to store values that are already encrypted and * encoded * * @param key * @param defaultValue * @return Unencrypted value of the key or the defaultValue if */ public String getStringUnencrypted(String key, String defaultValue) { final String nonEncryptedValue = SecurePreferencesOld.sFile.getString(SecurePreferencesOld.encrypt(key), null); return (nonEncryptedValue != null) ? nonEncryptedValue : defaultValue; }
@Override public String getString(String key, String defaultValue) { final String encryptedValue = SecurePreferencesOld.sFile.getString(SecurePreferencesOld.encrypt(key), null); return (encryptedValue != null) ? SecurePreferencesOld.decrypt(encryptedValue) : defaultValue; }