コード例 #1
0
 @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;
 }
コード例 #2
0
 @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());
   }
 }
コード例 #3
0
 @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;
 }
コード例 #4
0
 @Override
 public SharedPreferences.Editor remove(String key) {
   mEditor.remove(SecurePreferencesOld.encrypt(key));
   return this;
 }
コード例 #5
0
 @Override
 public SharedPreferences.Editor putBoolean(String key, boolean value) {
   mEditor.putString(
       SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Boolean.toString(value)));
   return this;
 }
コード例 #6
0
 @Override
 public SharedPreferences.Editor putFloat(String key, float value) {
   mEditor.putString(
       SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Float.toString(value)));
   return this;
 }
コード例 #7
0
 @Override
 public SharedPreferences.Editor putLong(String key, long value) {
   mEditor.putString(
       SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Long.toString(value)));
   return this;
 }
コード例 #8
0
 @Override
 public SharedPreferences.Editor putInt(String key, int value) {
   mEditor.putString(
       SecurePreferencesOld.encrypt(key), SecurePreferencesOld.encrypt(Integer.toString(value)));
   return this;
 }
コード例 #9
0
 /**
  * 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;
 }
コード例 #10
0
 @Override
 public boolean contains(String key) {
   return SecurePreferencesOld.sFile.contains(SecurePreferencesOld.encrypt(key));
 }
コード例 #11
0
 /**
  * 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;
 }
コード例 #12
0
 @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;
 }