![]() AES256-GCM is symmetric and generally fast on modern devices. It is a security specification in Jetpack Security, which is recommended for general use cases. Val mainKeyAlias = MasterKeys.getOrCreate(keyGenParameterSpec) ![]() You can create this by the following code: val keyGenParameterSpec = MasterKeys.AES256_GCM_SPEC The Key here is like a secure code used for the encryption/decryption purposes. Now you can use the EncryptedSharedPreferences. ![]() implementation "curity:security-crypto:1.0.0" To use the EncryptedSharedPreferences, first add the Jetpack Security library by adding this line app’s adle file. This file will contain all the data stored in SharedPreferences in the XML format. The normal_prefs is passed in the above line with calling getSharedPreferences() method. You will see a file with the name normal_prefs.xml in this directory. Open Device File Explorer, and then go to the data -> data -> YOUR_APP_PACKAGAE_NAME -> shared_prefs directory. Note that this requires any device/emulator is connected via USB Debugging. Once you have some data stored in the SharedPreferences, you can actually view that in Android Studio by opening Device File Explorer panel. Val intValue = preferences.getInt("Integer", 0) Val strValue = preferences.getString("String", "") Val boolValue = preferences.getBoolean("Bool", false) PutString("String", "Some normal string value") val preferences = getSharedPreferences("normal_prefs", MODE_PRIVATE) Normally, if you use SharedPreferences, you can use it by calling Context#getSharedPreferences() like the code below. Let’s now see how you can actually implement it in your Android apps easily. It also recommends to not use Android Keystore System (previously used for such purposes in Android) and choose Android’s Jetpack Security instead.Īnother interesting thing about Jetpack Security is that it also gives you a EncryptedSharedPreferences API separately, so that you use it directly instead of creating a wrapper around existing SharedPreferences. ![]() This helps you avoid using third-party libraries or writing your own custom encryption implementations like AES etc. Android Jetpack provides a new library Security which allows you to encrypt/decrypt data with a more robust and secure mechanism using a much friendly API. ![]()
0 Comments
Leave a Reply. |