public static final class Armadillo.Builder
extends java.lang.Object
ArmadilloSharedPreferences instance| Modifier and Type | Method and Description |
|---|---|
Armadillo.Builder |
addAdditionalDecryptionProtocolConfig(EncryptionProtocolConfig config)
Add new
EncryptionProtocolConfig to be added to the supported decryption-config
list. |
ArmadilloSharedPreferences |
build()
Build a
SharedPreferences instance |
Armadillo.Builder |
clearAdditionalDecryptionProtocolConfigs()
Clear additionalDecryptionConfigs list.
|
Armadillo.Builder |
compress()
Compresses the content with Gzip before encrypting and writing it to shared preference.
|
Armadillo.Builder |
compress(at.favre.lib.armadillo.Compressor compressor)
Compresses the content with given compressor before encrypting and writing it to shared preference.
|
Armadillo.Builder |
contentKeyDigest(byte[] salt)
The content key digest is responsible for hashing the key in the key-value pair of
a shared preference.
|
Armadillo.Builder |
contentKeyDigest(int contentKeyOutLength)
The content key digest is responsible for hashing the key in the key-value pair of
a shared preference.
|
Armadillo.Builder |
contentKeyDigest(StringMessageDigest stringMessageDigest)
The content key digest is responsible for hashing the key in the key-value pair of
a shared preference.
|
Armadillo.Builder |
cryptoProtocolVersion(int version)
Per default the crypto/data format version is '0', but if the behavior is changed by e.g.
|
Armadillo.Builder |
dataObfuscatorFactory(DataObfuscator.Factory dataObfuscatorFactory)
Set your own data obfuscation implementation.
|
Armadillo.Builder |
enableKitKatSupport(boolean enable)
Manually enable kitkatSupport.
|
Armadillo.Builder |
encryptionFingerprint(byte[] fingerprint)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(android.content.Context context)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(android.content.Context context,
byte[] additionalData)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(android.content.Context context,
java.lang.String... additionalData)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionFingerprint(EncryptionFingerprint fingerprint)
The encryption fingerprint is in important security measure.
|
Armadillo.Builder |
encryptionKeyStrength(int keyStrength)
Set the key length for the symmetric encryption.
|
Armadillo.Builder |
keyStretchingFunction(KeyStretchingFunction keyStretchingFunction)
Set a different key derivation function for provided password.
|
Armadillo.Builder |
password(char[] password)
Provide a user password used for encrypting all of values of the
SharedPreferences. |
Armadillo.Builder |
recoveryPolicy(boolean throwRuntimeException,
boolean removeBrokenContent) |
Armadillo.Builder |
recoveryPolicy(RecoveryPolicy recoveryPolicy) |
Armadillo.Builder |
secureRandom(java.security.SecureRandom secureRandom)
Provide your own
SecureRandom implementation. |
Armadillo.Builder |
securityProvider(java.security.Provider provider)
Set the security provider for most cryptographic primitives (symmetric encryption,
pbkdf2, ...).
|
Armadillo.Builder |
supportVerifyPassword(boolean supported)
Enabling support verify password allows you to use
ArmadilloSharedPreferences.isValidPassword()
to verify the validity of the user-provided password used to initialise Armadillo. |
Armadillo.Builder |
symmetricEncryption(AuthenticatedEncryption authenticatedEncryption)
Set your own implementation of
AuthenticatedEncryption. |
public Armadillo.Builder encryptionFingerprint(android.content.Context context)
EncryptionFingerprintFactory.context - used to gather sources from the Android OSpublic Armadillo.Builder encryptionFingerprint(android.content.Context context, byte[] additionalData)
context - used to gather sources from the Android OSadditionalData - provided additional custom datapublic Armadillo.Builder encryptionFingerprint(android.content.Context context, java.lang.String... additionalData)
context - used to gather sources from the Android OSadditionalData - provided additional custom datapublic Armadillo.Builder encryptionFingerprint(EncryptionFingerprint fingerprint)
fingerprint - fully custom instancepublic Armadillo.Builder encryptionFingerprint(byte[] fingerprint)
fingerprint - fully custom byte array containing the fingerprintpublic Armadillo.Builder contentKeyDigest(byte[] salt)
Settings.Secure#ANDROID_ID.
Note that changing the salt will make old data inaccessible, since the key won't match
anymore.salt - to be used for content key hash (should be > 16 byte)public Armadillo.Builder contentKeyDigest(int contentKeyOutLength)
Armadillo.CONTENT_KEY_OUT_BYTE_LENGTH
bytes long. If you think that is too long (wasting space) or too small (not enough entropy)
modify the length with this config.
contentKeyOutLength - to be used for content key hashpublic Armadillo.Builder contentKeyDigest(StringMessageDigest stringMessageDigest)
stringMessageDigest - custom implementationpublic Armadillo.Builder encryptionKeyStrength(int keyStrength)
Currently there are 2 options:
Note: Usually there is no real advantage to set it to VERY HIGH as HIGH (128 bit key length) is fully secure for the foreseeable future. VERY HIGH only adds more security margin for possible quantum computer attacks (but if you are a user which is threatened by these kinds of attacks you probably require higher degrees af protection).
keyStrength - HIGH (default) or VERY HIGHpublic Armadillo.Builder securityProvider(java.security.Provider provider)
provider - JCA providerpublic Armadillo.Builder symmetricEncryption(AuthenticatedEncryption authenticatedEncryption)
AuthenticatedEncryption. Use this if setting
the security provider with securityProvider(Provider) is not enough
customization. With this a any symmetric encryption algorithm might be used.
authenticatedEncryption - to be used by the shared preferencespublic Armadillo.Builder keyStretchingFunction(KeyStretchingFunction keyStretchingFunction)
ArmadilloBcryptKeyStretcher
is used. There is also a implementation PBKDF2 (see PBKDF2KeyStretcher. If you want
to use a different function (e.g. scrypt) set the implementation here.
If you want to disable the key stretching feature you might use FastKeyStretcher here.
keyStretchingFunction - to be used by the shared preferencespublic Armadillo.Builder dataObfuscatorFactory(DataObfuscator.Factory dataObfuscatorFactory)
HkdfXorObfuscator for the default obfuscation technique.
dataObfuscatorFactory - that creates a obfuscator with given keypublic Armadillo.Builder secureRandom(java.security.SecureRandom secureRandom)
SecureRandom implementation.
Per default a no-provider constructor is used for SecureRandom which
is the currently recommended way (https://tersesystems.com/blog/2015/12/17/the-right-way-to-use-securerandom/)
secureRandom - implementationpublic Armadillo.Builder recoveryPolicy(boolean throwRuntimeException, boolean removeBrokenContent)
public Armadillo.Builder recoveryPolicy(RecoveryPolicy recoveryPolicy)
public Armadillo.Builder password(char[] password)
SharedPreferences.
The password is treated as weak and is therefore subject to be stretched by the provided key
derivation function with key stretching property (see keyStretchingFunction(KeyStretchingFunction).
A side-effect is that putting or reading content is expensive and should not be done on the main thread.
A null password or zero length password will be treated as if no user-provided password was set.
If you want to be able to verify the password, set supportVerifyPassword(boolean)
to true and use ArmadilloSharedPreferences.isValidPassword() to verify.
By default, support verify password is disabled.
password - provided by userpublic Armadillo.Builder supportVerifyPassword(boolean supported)
ArmadilloSharedPreferences.isValidPassword()
to verify the validity of the user-provided password used to initialise Armadillo.
In order to verify the password, a known value is stored encrypted with the password the
first time that Armadillo is initialised. When ArmadilloSharedPreferences.isValidPassword()
is called, it tries to decrypt this value and compares it to the original value. If the values
match the validation succeeds, otherwise, it fails.
By default, support verify password is disabled.supported - true to supported password verification, false otherwisepublic Armadillo.Builder cryptoProtocolVersion(int version)
The protocol version will be used as additional associated data with the authenticated encryption.
version - to persist with the datapublic Armadillo.Builder compress()
public Armadillo.Builder compress(at.favre.lib.armadillo.Compressor compressor)
compressor - to setpublic Armadillo.Builder addAdditionalDecryptionProtocolConfig(EncryptionProtocolConfig config)
EncryptionProtocolConfig to be added to the supported decryption-config
list. That means, if you have encrypted data with an older encryption config you may add
it here to be able to decrypt it again. These configs are however never
used for encryption.
To match configs EncryptionProtocolConfig.protocolVersion is used, therefore if
you add a config here it must match the persisted protocolVersion (Armadillo default is
Armadillo.DEFAULT_PROTOCOL_VERSION)
This may be used for migration of encryption protocols.
config - to be added to the listpublic Armadillo.Builder clearAdditionalDecryptionProtocolConfigs()
addAdditionalDecryptionProtocolConfig(EncryptionProtocolConfig).public Armadillo.Builder enableKitKatSupport(boolean enable)
AesCbcEncryption) which uses CBC + Encrypt-then-mac which should have
a similar security strength.
The backwards compatible implementation will only be used if
Build.VERSION#SDK_INT is lower or equal to 19, the default version otherwise.
Additionally this implementation will be added to the additionalDecryptionConfigs so you
can still decrypt the old content after upgrading to lollipop and above (uses protocol-version
Armadillo.KITKAT_PROTOCOL_VERSION to mark.
enable - kitkat supportpublic ArmadilloSharedPreferences build()
SharedPreferences instance