public class SecureUserStore extends Object implements UserStore
User
) using Android built in KeyStore capabilities.
According to the Android API this picks the right algorithm to perfom the operations.
Prior to API 18 there were no AndroidKeyStore API, but the UNIX deamon existed to it's possible
with the help of this code: https://github.com/nelenkov/android-keystore.
On API > = 18, we generate an AES key to encrypt we then generate and uses the RSA key inside the KeyStore
to encrypt the AES key that we store along the encrypted data inside a private SharedPreferences
.
This throws a KeyStoreException
in case of an error or KeyStore being unvailable (unlocked).
See also: io.realm.internal.android.crypto.class.CipherClientCURRENT_USER_KEY
Constructor and Description |
---|
SecureUserStore(Context context) |
Modifier and Type | Method and Description |
---|---|
Collection<User> |
allUsers()
Returns a collection of all users saved in the User store.
|
User |
get(String key)
Retrieves the
User by decrypting first the serialised Json. |
User |
put(String key,
User user)
Store user as serialised and encrypted (Json), inside the private
SharedPreferences . |
User |
remove(String key)
Removes the user with the given key from the store.
|
public SecureUserStore(Context context) throws KeyStoreException
KeyStoreException
public User put(String key, User user)
SharedPreferences
.put
in interface UserStore
key
- the SharedPreferences
key.user
- we want to save.null
if no user was replaced.public User get(String key)
User
by decrypting first the serialised Json.get
in interface UserStore
key
- the SharedPreferences
key.User
with the given key.public User remove(String key)
UserStore
public Collection<User> allUsers()
UserStore