Android Jetpack Compose Encrypted Shared Preferences
Many times we want to save the data within the android application. This data is in the form of text and we generally prefer to store this data in the shared preferences. Shared preferences are not secure as we can simply view the data stored within the shared preferences and can easily access data within that file. In this article, we will take a look at How to use Encrypted Shared Preferences in android to store data securely within the android application using Jetpack Compose.
Step by Step Implementation
Step 1: Create a New Project in Android Studio
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.
Step 2: Adding a new color in the Color.kt file
Navigate to app > java > your app’s package name > ui.theme > Color.kt file and add the below code to it.
Step 3: Working with the MainActivity.kt file
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Now run your application to see the output of it.
Now check out the below article to check the value stored in the shared preferences How to View Data Stored in Shared Preferences in Android Studio. As we are using encrypted shared preferences we will get to see the data in the encrypted form. In the preferences.xml file, we will get to see the below data in the encrypted format. Encrypted shared preferences make it secure to store the data in shared preferences so anyone cannot access the data within our shared preferences.
Please Login to comment...