Member-only story
Step-by-Step Guide on Securing SharedPreferences in Android
Security is a very important topic and has to be taken seriously when developing Android apps. In this article, you will learn how you can encrypt SharedPreferences in Android with Jetpack’s Security library.
Written by Wajahat Karim and Saif Khan
Security is a very important topic and has to be taken seriously when developing Android applications, especially if sensitive data is stored on the device. In this article, we will learn how we can encrypt our Shared Preferences in Android using Jetpack’s Security library.
Normally, developers choose to implement AES encryption for securing data. But there is often the need for a “secret”. If this password or “secret” is hard-coded into your app or uses some system value like MAC address, anyone looking through a decompiled version of your code can easily decipher what it takes to decrypt the data. You could generate a random long secret but if you put it in regular SharedPreferences, it will get persisted in plain text and can become a security loophole.