Secure SharedPreferences

suggest change

Versions

[{“Name”:“1.0”,“GroupName”:null},{“Name”:“1.1”,“GroupName”:null},{“Name”:“1.5”,“GroupName”:null},{“Name”:“1.6”,“GroupName”:null},{“Name”:“2.0”,“GroupName”:null},{“Name”:“2.0.1”,“GroupName”:null},{“Name”:“2.1.x”,“GroupName”:null},{“Name”:“2.2.x”,“GroupName”:null},{“Name”:“2.3”,“GroupName”:null},{“Name”:“2.3.3”,“GroupName”:null},{“Name”:“3.0.x”,“GroupName”:null},{“Name”:“3.1.x”,“GroupName”:null},{“Name”:“3.2.x”,“GroupName”:null},{“Name”:“4.0”,“GroupName”:null},{“Name”:“4.0.3”,“GroupName”:null},{“Name”:“4.1”,“GroupName”:null},{“Name”:“4.2”,“GroupName”:null},{“Name”:“4.3”,“GroupName”:null},{“Name”:“4.4”,“GroupName”:null},{“Name”:“4.4W”,“GroupName”:null},{“Name”:“5.0”,“GroupName”:null},{“Name”:“5.1”,“GroupName”:null},{“Name”:“6.0”,“GroupName”:null},{“Name”:“7.0”,“GroupName”:null},{“Name”:“7.1”,“GroupName”:null}]

Introduction

Shared Preferences are key-value based XML files. It is located under /data/data/package_name/shared_prefs/<filename.xml>.

So a user with root privileges can navigate to this location and can change its values. If you want to protect values in your shared preferences, you can write a simple encryption and decryption mechanism.

You should know tough, that Shared Preferences were never built to be secure, it’s just a simple way to persist data.

Syntax

  1. public static String encrypt(String input);
  2. public static String decrypt(String input);

Parameters

Parameter| Definition | —— | —— | input | String value to encrypt or decrypt. |

Remarks

Shared Preferences were never built to be secure, it’s just a simple way to persist data.

It is not a good idea to use shared preferences for storing critical information such as user credentials. To save user credentials (such as passwords) you need to use other methods such as Android’s AccountManager.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Secure SharedPreferences:
* Secure SharedPreferences

Table Of Contents
2 Gradle
5 Intent
17 Service
19 WebView
31 SQLite
35 Glide
37 Dialog
38 ACRA
44 Handler
53 Toast
63 Menu
65 Picasso
70 Volley
71 Widgets
78 Realm
90 Spinner
95 OkHttp
108 TextView
109 ListView
111 Loader
118 Xposed
119 Security
121 ImageView
123 Doze Mode
130 Drawables
131 Colors
134 Fresco
139 AdMob
145 Keyboard
146 Button
150 EditText
155 Vk SDK
163 ExoPlayer
169 XMPP
175 OpenCV
177 Threads
184 ORMLite
186 TabLayout
190 LruCache
192 Zip files
194 Fastlane
199 FileIO
202 Moshi
210 VideoView
216 Paint
218 ProGuard
226 CleverTap
228 ADB shell
229 Ping ICMP
230 AIDL
234 Context
236 Secure SharedPreferences
240 JCodec
242 Okio
249 FuseView
254 Looper
261 Fastjson
263 Jackson
267 Smartcard