public class StringCipher
extends java.lang.Object
This uses SharedPreferences to save the salt of encryption. Please specify a unique name
as the constructor parameter that represents Shared Preference name.
Either first access of encrypt(Context, String), decrypt(Context, String) or
initialize(Context) is very slow because there is secret key generation with PBKDF2.
We recommend that you initialize an instance of this class beforehand and cache it.
| Constructor and Description |
|---|
StringCipher(java.lang.String sharedPreferenceName) |
StringCipher(java.lang.String sharedPreferenceName,
int pbkdf2IterationCount,
boolean isSerialIncludedInDevicePackageSpecificId) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
decrypt(android.content.Context context,
java.lang.String b64CipherText) |
java.lang.String |
encrypt(android.content.Context context,
java.lang.String plainText) |
void |
initialize(android.content.Context context) |
public StringCipher(java.lang.String sharedPreferenceName)
public StringCipher(java.lang.String sharedPreferenceName,
int pbkdf2IterationCount,
boolean isSerialIncludedInDevicePackageSpecificId)
sharedPreferenceName - shared pref name used to save saltpbkdf2IterationCount - number of iteration used for encryptionisSerialIncludedInDevicePackageSpecificId - Indicates if we should also include Build.Serial as an identifier to generate
the device Id.
Note : This field should always be false as it is deprecated and
returns UNKNOWN in some cases from Android SDK >= 27