Class CredentialsManager
Stored values are encrypted with a "master password" (=encryption key). If this has not yet been supplied to the encryption engine, the user will be prompted to create it. Upon creating a master password, a "canary" value is saved to preferences; the canary is used to ensure that all values are encrypted with the same master password (thus ensuring that the user only needs to remember one password).
The user can choose not to set a master password; in this case a master password is generated for the user and stored in Preferences in plain text. Values stored with the CredentialsManager will still be encrypted, but because the master password is readily accessible the actual security is greatly diminished. This feature was deemed required for usability, despite the drawbacks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classstatic enum -
Method Summary
Modifier and TypeMethodDescriptionvoidClear the value for the given key.voidClear the stored master password (if present) and the canary value.static CredentialsManagerbooleanCheck whether or not the master password has been set.booleanCheck whether or not the master password is stored in plain text so the user doesn't need to input it.booleanCheck to see if a value has been securely stored for the given key.Retrieve the securely stored value for the given key.booleanSecurely store a key-value pair.
-
Method Details
-
getInstance
-
store
Securely store a key-value pair. If the master password is not stored and has not been input, the user will be prompted to input it.- Parameters:
key- The key for the value to store (not encrypted)value- The value to store (encrypted)- Returns:
- True if the value was stored successfully; false if otherwise (e.g. the user canceled)
-
isStored
Check to see if a value has been securely stored for the given key.If the master password has not been set, this will return false for all keys.
- See Also:
-
isMasterPasswordSet
public boolean isMasterPasswordSet()Check whether or not the master password has been set. This checks only for the presence of the canary value. -
isMasterPasswordStored
public boolean isMasterPasswordStored()Check whether or not the master password is stored in plain text so the user doesn't need to input it. The master password is considered to not be stored ifisMasterPasswordSet()returns false. -
clearMasterPassword
public void clearMasterPassword()Clear the stored master password (if present) and the canary value. Afterwards, any encrypted values will be considered to be not set (isStored(String)returns false;retrieve(String)returnsOptional.empty()). -
clear
Clear the value for the given key. -
retrieve
Retrieve the securely stored value for the given key. If the master password is not stored and has not been input, the user will be prompted to input it.- Parameters:
key- The key for the value to store (not encrypted)- Returns:
- The Optional-wrapped value, which can be empty if the user declines to enter the master password or the master password is not the correct encryption key for the value
-