androidencryptionsharedpreferencespassword-encryption

Android encrypt edittext input


I'm building Android app that is intended for exactly one user per installation. Application needs to store username and password.

After validation, entered username and password are stored in shared preferences and both of them need to be entered every time the app starts.

Username field:android:inputType="textCapSentences"

Password field:android:inputType="textPassword"

My question is: what is the least painful way to encrypt/decrypt both values.

Encryption process doesn't have to be top notch since the application is for school project.


Solution

  • There is no need to encrypt/decrypt the inputs.

    In order to make them unreadable you just have to use a good one-to-one Hash-Function.

    Let's say your hash function is 'h':

    To store your values:

    // Pseudo
    SharedPrefs.put(USERNAME, h(input_username));
    

    To validate your values:

    // Pseudo
    SharedPrefs.get(USERNAME).equals(h(input_username));