public static final class CryptoSharedPreferences.Builder extends Object
CryptoSharedPreferences with a desired
configuration.
CryptoSharedPreferences via build() successfully.
#Builder(SharedPreferences)valueCrypto(Crypto)| Constructor and Description |
|---|
Builder(SharedPreferences preferences)
Creates a new instance of Builder with the given shared preferences instance.
|
| Modifier and Type | Method and Description |
|---|---|
CryptoSharedPreferences |
build()
Builds a new instance of CryptoSharedPreferences with the configuration specified for
this builder.
|
CryptoSharedPreferences.Builder |
keyCrypto(Crypto crypto)
Specifies an implementation of
Crypto that should be used by CryptoSharedPreferences
for encryption and decryption of preference keys for which are values persisted
in preferences specified via #Builder(SharedPreferences). |
CryptoSharedPreferences.Builder |
valueCache(SharedPreferencesCache cache)
Specifies a cache that should be used by
CryptoSharedPreferences to store already
decrypted preference values in order to speed up obtaining process of such values
from shared preferences. |
CryptoSharedPreferences.Builder |
valueCrypto(Crypto crypto)
Specifies an implementation of
Crypto that should be used by CryptoSharedPreferences
for encryption and decryption of preference values persisted in preferences
specified via #Builder(SharedPreferences). |
public Builder(@NonNull SharedPreferences preferences)
preferences - The preferences instance that will be used by CryptoSharedPreferences
for persistence of encrypted values.public CryptoSharedPreferences.Builder keyCrypto(@Nullable Crypto crypto)
Crypto that should be used by CryptoSharedPreferences
for encryption and decryption of preference keys for which are values persisted
in preferences specified via #Builder(SharedPreferences).
Note, that when key crypto is specified all OnSharedPreferenceChangeListener
listeners that are registered via SharedPreferences.registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener)
will be notified with already decrypted key of the changed preference. However any
change listener that is registered directly on the encrypted preferences instance will
be notified with encrypted key of the changed preference. It is recommended to
use registration method of CryptoSharedPreferences so the listeners do not need
to deal with decryption of the preference keys nor values.
See Keys Encryption section in description of CryptoSharedPreferences for
more information.
crypto - The desired crypto implementation. May be null to not encrypt nor
decrypt preference keys.valueCrypto(Crypto)public CryptoSharedPreferences.Builder valueCrypto(@NonNull Crypto crypto)
Crypto that should be used by CryptoSharedPreferences
for encryption and decryption of preference values persisted in preferences
specified via #Builder(SharedPreferences).
If encryption and decryption of preference values shows up as a time consuming operation
that slows up putting and obtaining of those values from shared preferences a cache may
be specified via valueCache(SharedPreferencesCache). This cache will be then used
by CryptoSharedPreferences for storing of already decrypted preference values
so such values may be obtained in a much faster fashion.
See Values Encryption section in description of CryptoSharedPreferences for
more information.
crypto - The desired crypto implementation to be used for values encryption/decryption.keyCrypto(Crypto)public CryptoSharedPreferences.Builder valueCache(@Nullable SharedPreferencesCache cache)
CryptoSharedPreferences to store already
decrypted preference values in order to speed up obtaining process of such values
from shared preferences.
See Caching section in description of CryptoSharedPreferences for more
information.
cache - The desired cache for decrypted preference values. May be null to not
cache decrypted values.valueCrypto(Crypto)@NonNull public CryptoSharedPreferences build()
IllegalArgumentException - If some of the required parameters is missing.