Given that it is not possible to store a symmetric key using the Android KeyChain API, is the following a secure way to store a symmetric key:
Part One: Key Generation and Storage
- Generate
symmetric_key - Generate
(private_key, public_key), store them in theKeyChain - Encrypt the
symmetric_keyusing thepublic_keyas follows:encrypted_symmetric_key = public_encrypt(symmetric_key) - Store
encrypted_symmetric_keyin local storage (SharedPreferences,SQLite, etc.)
Part Two: Using the symmetric_key
When the app wants to encrypt/decrypt something it:
- Loads the
private_keyinto memory from theKeyChain - Loads the
encrypted_symmetric_keyfrom disk - Obtains
symmetric_key := private_decrypt(encrypted_symmetric_key) encrypt(symmetric_key, some_message)ordecrypt(symmetric_key, some_ciphertext)
Concerns:
- Would a rooted user be able to obtain the
(private_key, public_key)pair? - If the phone is not rooted, is the app that created the
(private_key, public_key)pair the only user that can read the keypair?