@Override public Map<String, String> getAll() { final Map<String, ?> encryptedMap = SecurePreferencesOld.sFile.getAll(); final Map<String, String> decryptedMap = new HashMap<String, String>(encryptedMap.size()); for (Entry<String, ?> entry : encryptedMap.entrySet()) { try { decryptedMap.put( SecurePreferencesOld.decrypt(entry.getKey()), SecurePreferencesOld.decrypt(entry.getValue().toString())); } catch (Exception e) { // Ignore unencrypted key/value pairs } } return decryptedMap; }
@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 String getString(String key, String defaultValue) { final String encryptedValue = SecurePreferencesOld.sFile.getString(SecurePreferencesOld.encrypt(key), null); return (encryptedValue != null) ? SecurePreferencesOld.decrypt(encryptedValue) : defaultValue; }